/****************************************************************************** * Programme : Instruction BY : Maîtrisez le traitement par groupes dans l'étape DATA SAS * Reference : EXEMPLC0D5 * Source : https://www.wearecas.eu/en/sampleCode/EXEMPLC0D5 ******************************************************************************/ /* --- BLOC 1 --- */ data zip; input zipCode State $ City $ Street $20-29; datalines; 85730 AZ Tucson Domenic Ln 85730 AZ Tucson Gleeson Pl 33133 FL Miami Rice St 33133 FL Miami Thomas Ave 33133 FL Miami Surrey Dr 33133 FL Miami Trade Ave 33146 FL Miami Nervia St 33146 FL Miami Corsica St 33801 FL Lakeland French Ave 33809 FL Lakeland Egret Dr ; proc sort data=zip; by zipCode; run; data zip; set zip; by zipCode; run; proc print data=zip noobs; title 'BY-Group Uing a Single Variable: ZipCode'; run; /* --- BLOC 2 --- */ data zip; input State $ City $ Street $13-22 ZipCode ; datalines; FL Miami Nervia St 33146 FL Miami Rice St 33133 FL Miami Corsica St 33146 FL Miami Thomas Ave 33133 FL Miami Surrey Dr 33133 FL Miami Trade Ave 33133 FL Lakeland French Ave 33801 FL Lakeland Egret Dr 33809 AZ Tucson Domenic Ln 85730 AZ Tucson Gleeson Pl 85730 ; proc sort data=zip; by State City; run; data zip; set zip; by State City; run; proc print data=zip noobs; title 'BY Groups with Multiple BY Variables: State City'; run; /* --- BLOC 3 --- */ options linesize=80 pagesize=60; data test; input name $ Score; datalines; Jon 1 Anthony 3 Miguel 3 Joseph 4 Ian 5 Jan 6 ; proc format; value Range 1-2='Low' 3-4='Medium' 5-6='High'; run; data newtest; set test; by groupformat Score; format Score Range.; run; proc print data=newtest; title 'Score Categories'; var Name Score; by Score; run;