Problem/Requirement -
Lets Suppose, We have Data in Numbers which could be range from 100 to 10000
now we want to create Groups of Each 100 Values, like below -
now we want to create Groups of Each 100 Values, like below -
/*This code will Generate some Numbers between 100 and 10000 to Get the Practice Dataset */
Data A;
Num=100;
Do while(Num<10000);
output;
Num=Num+54;
end;
Run;
Proc Print Data=A;
Run;
/* This Code will Genrate FMTName (Format Name), Start(Starting Number of Group), End(Ending Number of Group), Label(Group name for Numbers between Start and End Values)
*/
Data B;Retain FMTName "Group";Start=100;i=1;Do until(End>=10000);End=Start+99;Label=compbl("Group"||i);Output;Start=End+1;i=i+1;end;drop i;run;Proc Print Data=B;Run;
/* This wil create a format for Above created B Dataset with Format Name "Group", PROC FORMAT with the CNTLIN= option is to build the formats from the imported control data set */
Proc Format CNTLIN=B;Run;
/*Lets see how it will print A Dataset if we apply Newly create Group format to Variable Num */
Proc Print Data=A;
Format Num Group.;run;
/* If we want Actual Number and the Group name both the things then we can do it like this */
Data C;Set A;GroupName=Put(Num,Group.);run;
/*Here we created a new Variable Group name and Copy value of Num with Group format, For this we used PUT Function */
Proc Print Data=C;Run;
I Hope you like this Article, please comment if you have any doubt or question.
Thank you
0 Comments
If you have any doubt please comment or write us to - admin@datahark.com