Advertisement
Guest User

TP0

a guest
Aug 14th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SAS 10.57 KB | None | 0 0
  1. LIBNAME LIBRARY 'D:\Users\AdelinouxX\Desktop\Travail_SAS\FORMAT';
  2. LIBNAME OUT 'D:\Users\AdelinouxX\Desktop\Travail_SAS\DATA';
  3.  
  4. /* --------------------------------------------------------------------------------------------------------------------------------
  5.     ETAPE 2 : S?lection  et des variables
  6.     - Cr?ez un nouveau dataset permanent "ess2012VF" (? stocker dans la librairie OUT)? partir du dataset ESS6E02_1_F1
  7.     - Conservez uniquement la liste de variables suivantes au moyen d'un KEEP statement :
  8.         - Variable d'int?r?t : DMCNTOV
  9.         - Explicatives socio-d?mographiques : REGION EISCED HINCFEL AGEA         
  10.         - Explicatives "th?matiques" : POLINTR BLGETMG PLINSOC
  11. /* --------------------------------------------------------------------------------------------------------------------------------*/
  12.  
  13. data out.ess2016VF;
  14.     set out.ESS8e02_0_F1;
  15.     keep AESFDRK AGEA basinc dfincac DOMICIL EISCED emplrel GNDR HAPPY health HINCFEL icpart1 lknemny imprich impfree inprdsc ipeqopt iphlppl lvgptnea MNACTIC PPLTRST RLGDGR SBLAZY sblwcoa SCLMEET sclact wkhtot;
  16. run;
  17.    
  18.  
  19. *NB : V?rifiez que le dataset a bien ?t? cr??
  20.         - via le log : NOTE: The data set OUT.ESS2012VF has 1869 observations and 8 variables.
  21.         - via la fen?tre Explorateur --> Biblioth?ques --> OUT --> double-clic sur le dataset Ess2012vf --> VIEWTABLE
  22. !!!! Veillez ? toujours fermer la VIEWTABLE avant d'ex?cuter la suite du programme !!!!;
  23.  
  24.  
  25. /* -------------------------------------------------------------------------------------
  26.     ETAPE 3 : Examiner les caract?ristiques des variables retenues via la PROC CONTENTS
  27.               Que constate-t-on?
  28.    ------------------------------------------------------------------------------------- */
  29.  
  30. proc contents data = out.ess2016VF varnum;
  31. run;
  32.  
  33. /* -----------------------------------------------------------------------------------------------------------------
  34.     ETAPE 4 : Cr?ez un format "age" pour discr?tiser la variable AGEA de la mani?re suivante ? l'aide de PROC FORMAT
  35.               <20 ; [20-30[; [30-40[; [40; 50[; [50-60[; [60-70[; [70-80[; >=80
  36.               Stocker le format dans la librairie LIBRARY
  37.    ----------------------------------------------------------------------------------------------------------------- */
  38.  
  39. proc format library = library;
  40.     value age low-<20 = '<20'
  41.               20-<30 = '[20-30['
  42.               30-<40 = '[30-40['
  43.               40-<50 = '[40-50['
  44.               50-<60 = '[50-60['
  45.               60-<70 = '[60-70['
  46.               70-<80 = '[70-80['
  47.               80-high = '>=80';
  48. run;
  49.  
  50.  
  51. /* ---------------------------------------------------------------------------------------------------------------------------------------
  52.     ETAPE 5 : Appliquer la PROC FREQ sur l'ensemble des variables
  53.               Assigner le format age ? la variable agea pour observer les effectifs par cat?gorie plut?t que pour
  54.               chaque valeur sp?cifique de la variable continue (NB : l'assignation est temporaire dans un bloc PROC)
  55.               Utiliser l'option NLEVELS pour afficher ?galement la liste du nombre de niveaux.  
  56.               Dirigez les sorties vers un fichier pdf qui sera stock? dans le sous-dossier RESULTS que vous avez cr?? dans votre espace de travail.
  57.               Pour ce faire, utilisez l'instruction ODS, appliquez le style "Journal", supprimez l'affichage de la date et donnez
  58.               le titre suivant ? votre rapport : 'Distribution des variables initiales'.
  59.    --------------------------------------------------------------------------------------------------------------------------------------- */
  60.  
  61. ods pdf file = 'D:\Users\AdelinouxX\Desktop\Travail_SAS\results\rapport1.pdf' style = journal;
  62. options nodate;
  63. title 'Distribution des variables initiales';
  64.  
  65. proc freq data = out.ess2016VF nlevels;
  66.     format agea age.;
  67. run;
  68.  
  69. title;
  70. ods pdf close;
  71.  
  72.  
  73. /*  ---------------------------------------------------------------------------------------------------------------
  74.     ETAPE 6 : Cr?er de nouvelles variables pour recoder les variables initiales via des IF THEN ELSE statements.
  75.     En tenant compte de la r?partition des effectifs, regroupez les cat?gories de mani?re pertinente pour d?finir
  76.     les nouvelles variables suivantes :  
  77.     1. La variable d'int?r?t doit ?tre recat?goris? en 2 niveaux (EVALDEMO2) en 4 niveaux (EVALDEMO4)
  78.     2. POLINTR et HINCFEL doivent ?tre recat?goris?es en 2 niveaux au d?part de 4 (POLINTR2 HINCFEL2)
  79.     3. EISCED doit ?tre recod?e en 3 niveaux (EDUC3 : "Low", "Middle", "High")
  80.     4. PLINSOC doit ?tre recod?e en 3 niveaux (PLINSOC3 : "Top", "Middle", "Bottom")
  81.     5. REGION doit ?tre recod?e en 3 niveaux (REG3 : "Bxl", "Fl", "Wal")
  82.     Le nouveau dataset permanent doit s'appeler "datarecod".
  83.     --------------------------------------------------------------------------------------------------------------- */
  84.  
  85. data out.datarecod;
  86.     length basinc2 $ 9 dfincac2 $ 15 HAPPY3 $ 22  health3 $ 17 inprdsc3 $ 11 sclact2 $ 11 sblazy3 $ 9 impfree3 $ 16 imprich3 $ 16
  87.       lknemny3 $ 13 sblwcoa3 $ 9 iphlppl3 $ 16 ipeqopt3 $ 16 hincfel2 $ 16 educ3 $ 9 domicil2 $ 16 mnactic2 $ 10 ppltrst3 $ 17 sclmeet2 $ 11 aesfdrk2 $ 13 rlgdgr3 $ 16 wkhtot3 $ 21 ;
  88.     set out.ess2016VF ;
  89.  
  90.     *1. La variable d'int?r?t recat?goris?e en 2 et en 4 niveaux;
  91.  
  92.     if 1 <= dfincac <= 2 then dfincac2 = 'A)D accord' ;
  93.     else if 3 <= dfincac <= 5 then dfincac2 = 'B) Pas d accord' ;
  94.  
  95.     if 0 <= HAPPY <= 7 then HAPPY3 = 'A)Malheureux' ;
  96.     else if 8 <= HAPPY <= 8 then HAPPY3 = 'B) Moyennement heureux' ;
  97.     else if 9 <= HAPPY <= 10 then HAPPY3 = 'C) Heureux' ;
  98.  
  99.     if basinc  in (1,2) then basinc2 = "A) Contre";
  100.     else if basinc  in (3,4) then basinc2 = "B) Pour";
  101.  
  102.     if 0 <= inprdsc <= 3 then inprdsc3 = 'A) Peu' ;
  103.     else if 4 <= inprdsc <= 4 then inprdsc3 = 'B) Moyen' ;
  104.     else if 5 <= inprdsc <= 6 then inprdsc3 = 'C) Beaucoup' ;
  105.  
  106.     if 1 <= health <= 2 then health3 = 'A) Bonne santé' ;
  107.     else if 3 <= health <= 3 then health3 = 'B) Neutre' ;
  108.     else if 4 <= health <= 5 then health3 = 'C) Mauvaise santé' ;
  109.    
  110.     if 1 <= sclact <= 2 then sclact2 = 'A) Peu' ;
  111.     else if 3 <= sclact <= 5 then sclact2 = 'B) Beaucoup' ;
  112.  
  113.     if 1<= HINCFEL <=2 then HINCFEL2='A) Confortable' ;
  114.     else if 3<= HINCFEL <=4 then HINCFEL2='B) Difficile' ;
  115.  
  116.     if DOMICIL  in (1,2,3) then DOMICIL2 = "A) Plutôt urbain";
  117.     else if DOMICIL in (4,5) then DOMICIL2 = "B) Plutôt rural";
  118.    
  119.     if mnactic in (1,2) then mnactic2 = "A) Actif";
  120.     else if mnactic in (3,4,5,6,7,8) then mnactic2 = "B) Inactif";
  121.  
  122.     else if 0 <= ppltrst <= 4 then ppltrst3 = 'A) Peu confiant' ;
  123.     else if 5 <= ppltrst <= 6 then ppltrst3 = 'B) Assez confiant' ;
  124.     else if 7 <= ppltrst <= 10 then ppltrst3 = 'Très confiant' ;
  125.  
  126.     if 1 <= sclmeet <= 5 then sclmeet2 = 'A) Peu' ;
  127.     else if 6 <= sclmeet <= 7 then sclmeet2 = 'B) Beaucoup' ;
  128.  
  129.     if 1 <= sblazy <= 2 then sblazy3 = 'A) Oui' ;
  130.     else if 3 <= sblazy <= 3 then sblazy3 = 'B) Neutre' ;
  131.     else if 4 <= sblazy <= 5 then sblazy3 = 'C) Non' ;
  132.  
  133.     if 1 <= impfree <= 1 then impfree3 = 'A) Important' ;
  134.     else if 2 <= impfree <= 2 then impfree3 = 'B) Neutre' ;
  135.     else if 3 <= impfree <= 6 then impfree3 = 'C) Pas important' ;
  136.    
  137.     if 1 <= imprich <= 2 then imprich3 = 'A) Important' ;
  138.     else if 3 <= imprich <= 3 then imprich3 = 'B) Neutre' ;
  139.     else if 4 <= imprich <= 6 then imprich3 = 'C) Pas important' ;
  140.  
  141.     if 1 <= iphlppl <= 2 then iphlppl3 = 'A) Important' ;
  142.     else if 3 <= iphlppl <= 3 then iphlppl3 = 'B) Neutre' ;
  143.     else if 4 <= iphlppl <= 6 then iphlppl3 = 'C) Pas important' ;
  144.  
  145.     if 1 <= ipeqopt <= 1 then ipeqopt3 = 'A) Important' ;
  146.     else if 2 <= ipeqopt <= 2 then ipeqopt3 = 'B)Neutre' ;
  147.     else if 3 <= ipeqopt <= 6 then ipeqopt3 = 'C) Pas important' ;
  148.  
  149.     if 1 <= sblwcoa <= 2 then sblwcoa3 = 'A) Oui' ;
  150.     else if 3 <= sblwcoa <= 3 then sblwcoa3 = 'B) Neutre' ;
  151.     else if 4 <= sblwcoa <= 5 then sblwcoa3 = 'C) Non' ;
  152.  
  153.     if aesfdrk in (1,2) then aesfdrk2 = 'A) Sécurisé';
  154.     else if aesfdrk in (3,4) then aesfdrk2 = 'B) Insécurisé';
  155.  
  156.     if 1 <= lknemny <= 1 then lknemny3 = 'A) Pas du tout' ;
  157.     else if 2 <= lknemny <= 2 then lknemny3 = 'B) Plutôt pas' ;
  158.     else if 3 <= lknemny <= 4 then lknemny3 = 'C) Assez' ;
  159.  
  160.     if 0 <= rlgdgr <= 2 then rlgdgr3 = 'A) Pas religieux' ;
  161.     else if 3 <= rlgdgr <= 6 then rlgdgr3 = 'B) Peu religieux' ;
  162.     else if 7 <= rlgdgr <= 10 then rlgdgr3 = 'C) Religieux' ;
  163.  
  164.     if 1 <= EISCED <=2 then educ3 = "A) Peu";
  165.     else if 3 <= EISCED <= 5 then educ3 = "B) Moyen";
  166.     else if 6 <= EISCED <= 7 then educ3 = "C) Haut";
  167.  
  168.     if 1 <= wkhtot <= 36 then wkhtot3 = "A) Moins de 37h/sem";
  169.     else if 37 <= wkhtot <= 42 then wkhtot3 = "B) De 37 à 42h/sem";
  170.     else if 43 <= wkhtot <= 156 then wkhtot3 = "C) Plus de 42h/sem";
  171.  
  172.     run;
  173.  
  174.     proc contents data = out.datarecod varnum;
  175. run;  
  176.  
  177.  
  178. data out.datalabel;
  179.     set out.datarecod;
  180.     label
  181. basinc2 = 'Against or In favour of a basic income scheme - 2 levels'
  182. dfincac2 = 'Large differences in income acceptable to reward talents and efforts - 2 levels'
  183. HAPPY3 = 'How happy are you - 3 levels'
  184. health3 = 'Subjective general health - 3 levels'
  185. inprdsc3 = 'How many people with whom you can discuss intimate and personal matters - 3 levels'
  186. sclact2 = 'Take part in social activities compared to others of same age - 2 levels'
  187. sblazy3 = 'Social benefits/services make people lazy - 3 levels'
  188. impfree3 = 'Important to make own decisions and be free - 3 levels'
  189. imprich3 = 'Important to be rich, have money and expensive things - 3 levels'
  190. lknemny3 = 'How likely not enough money for household necessities next 12 months - 3 levels'
  191. sblwcoa3 = 'Social benefits/services make people less willing care for one another - 3 levels'
  192. iphlppl3 = 'Important to help people and care for others well-being - 3 levels'
  193. ipeqopt3 = 'Important that people are treated equally and have equal opportunities - 3 levels'
  194. hincfel2 = 'Feeling about household s income nowadays - 2 levels'
  195. educ3 = 'Highest level of education, ES - ISCED - 3 levels'
  196. domicil2 = 'Domicile, respondent s description - 2 levels'
  197. mnactic2 = 'Main activity, last 7 days. All respondents. Post coded - 2 levels'
  198. ppltrst3 = 'Most people can be trusted or you can t be too careful - 3 levels'
  199. sclmeet2 = 'How often socially meet with friends, relatives or colleagues - 2 levels'
  200. aesfdrk2 = 'Feeling of safety of walking alone in local area after dark - 2 levels'
  201. rlgdgr3 = 'How religious are you - 3 levels' ;
  202. run;
  203.  
  204. proc contents data = out.datalabel varnum;
  205. run;  
  206.  
  207. ods pdf file = 'D:\Users\AdelinouxX\Desktop\Travail_SAS\RESULTS\rapport2.pdf' style = journal;
  208.  
  209. title1 'Evaluation de la d?mocratie en Belgique';
  210. title2 'Variables explicatives socio-d?mographiques';
  211.  
  212. proc freq data = out.datalabel;
  213.     tables
  214.  
  215. health3*happy3
  216. sclact2*happy3
  217. lknemny3*happy3
  218. sblwcoa3*happy3
  219. hincfel2*happy3
  220. sclmeet2*happy3
  221.  
  222. /nopercent nocol;
  223.  
  224. run;  
  225.  
  226. title;
  227. ods pdf close ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement