1 / 18

Trucs et astuces

Trucs et astuces. Souvent, on me demande encore. Retenir certaines colonnes. Étape data : set Fichier (keep= CITY STATE STATECODE STATENAME); set Ficher (keep=CITY STAT:);. Retenir certaines colonnes , option 2. macro Garder : %macro garder(Table,Cherche); %global varlist;

imaran
Download Presentation

Trucs et astuces

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Trucs et astuces Souvent, on me demande encore...

  2. Retenir certaines colonnes • Étape data : set Fichier (keep= CITY STATE STATECODE STATENAME); set Ficher (keep=CITY STAT:);

  3. Retenircertainescolonnes, option 2 • macro Garder : %macro garder(Table,Cherche); %global varlist; %let dsid = %sysfunc(open(&Table,i)); %let varlist =; %do i=1 %to %sysfunc(attrn(&dsid,nvars)); %if %index(%sysfunc(varname(&dsid,&i)),%sysfunc(upcase(&Cherche))) gt 0 %then %let varlist=&varlist %sysfunc(varname(&dsid,&i)); %end; %put varlist=&varlist; %mend garder;

  4. Importer un fichier plat • SASHELP.ZipCode: proc contents data=SASHELP.ZipCode out=Attributs(keep=NAME VARNUM TYPE LENGTH); run; proc sort data=Attributs; by VARNUM; run; data Attributs; set Attributs; if TYPE = 1 then Format = compress(LENGTH||'.'); else Format = compress('$'||LENGTH||'.'); run;

  5. Importer un fichier plat Attributs

  6. Importer un fichier plat (suite) data _null_; length Ligne $5000.; file Put_File; put 'data Source;'; Ligne = 'infile "/home/gen00279/LaCapitale/BackUps/Source.txt" firstobs=2 '||"delimiter=';' MISSOVER DSD lrecl=5000;"; put @4 Ligne; dsid = open('Attributs','i'); Ligne = ''; do Roule = 1 to attrn(dsid,'nobs'); rc = fetch(dsid); Variable = getvarc(dsid,varnum(dsid,'NAME')); Format = getvarc(dsid,varnum(dsid,'Format')); Ligne = trim(Ligne)||' '||compress(Variable)||' '||compress(Format); end; rc = close(dsid); Ligne = 'length'||trim(Ligne)||';'; put @4 Ligne;

  7. Importer un fichier plat (suite) dsid = open('Attributs','i'); do Roule = 1 to attrn(dsid,'nobs'); Posit = 10; rc = fetch(dsid); Variable = getvarc(dsid,varnum(dsid,'NAME')); Format = getvarc(dsid,varnum(dsid,'Format')); if substr(Format,1,1) = '$' then Type = '$'; else Type = ''; if Roule = 1 then do; Posit = 4; Ligne = 'input '||compress(Variable)||' '||Type; end; else Ligne = compress(Variable)||' '||Type; if Roule = attrn(dsid,'nobs') then Ligne = trim(Ligne)||';'; put @Posit Ligne; end; rc = close(dsid);

  8. Importer un fichier plat (suite) put 'run;'; run; %include Put_File;

  9. Importer un fichier platCode généré data Source; infile "/home/gen00279/LaCapitale/BackUps/Source.txt" firstobs=2 delimiter=';' MISSOVER DSD lrecl=5000; length ZIP 8. Y 8. X 8. ZIP_CLASS $1. CITY $35. STATE 8. STATECODE $2. STATENAME $25. COUNTY 8. COUNTYNM $25. MSA 8. AREACODE 8. TIMEZONE $9. GMTOFFSET 8. DST $1. PONAME $28.; input ZIP Y X ZIP_CLASS $ CITY $ STATE STATECODE $ …. TIMEZONE $ GMTOFFSET DST $ PONAME $; run;

  10. Importer un fichier plat Fichier Source

  11. Sélection aléatoire filename Put_File "/work1/Generer.sas"; data Source; Ligne = _n_; set Source; run; %let dsid=%sysfunc(open(Source)); %let NbRow=%sysfunc(attrn(&dsid,nobs)); %let rc=%sysfunc(close(&dsid));

  12. Sélection aléatoire data _null_; length Ligne $256.; file Put_File; put "data Selection;"; put " set Source;"; do n=1 to 100; Ligne = "if _n_ = "||compress(int(ranuni(today())*&NbRow.))||" then output;"; put @4 Ligne; end; put "run;"; run; %include Put_File

  13. Sélection aléatoireCode généré data Selection; set Source; if _n_ = 6632 then output; if _n_ = 41314 then output; if _n_ = 4395 then output; if _n_ = 11798 then output; if _n_ = 24266 then output; if _n_ = 32161 then output; …. if _n_ = 13008 then output; if _n_ = 10188 then output; if _n_ = 24245 then output; run;

  14. Sélection aléatoireTable générée

  15. Lecture du LOG

  16. Lecture du LOG • Commandes ajoutées à l’autoexec : dm log "color warning green reverse" continue; dm log "color error red reverse" continue;

  17. Lecture du LOG

  18. Questions, commentaires. Normand LétourneauENL Info Solutions inc.normand.letourneau@enlinfosolutions.ca (514) 993-9230

More Related