I have 4 string variables 'EMS_TC_ICD9_1 through EMS_TC_ICD9_4' . I want to aggreagate them into larger cartegories and create 4 new group variables. I thought using a MACRO would be more efficient than running the Data Step 4 times but can't get it to run.
Also I have no idea how to get the MACRO to recognize the PROC FORMAT or what's an alternate workaround.
END RESULT: I want to create 4 new numeric variables 'EMS_TC_ICD9_GRP1 through EMS_TC_ICD9_GRP4 and assign names to the different categories.
I didn't get any errors but this is definitely wrong - new variables were not created.
WHere did I go wrong?
1922 options mprint nosymbolgen;
1923
1924 %MACRO ICD9(varnum, var, grpvar);
1925
1926 DATA TC_viaEMS_cleaning1;
1927 SET TC_viaEMS_cleaning;
1928
1929 %do i=1 %to &varnum;
1930
1931 %if EMS_TC_ICD9_&i="BL" or EMS_TC_ICD9_&i="*ND" %then %do;
1932 EMS_TC_ICD9_grp&i=.;
1933 %end;
1934
1935 %else %do;
1936 %if "800.00" le EMS_TC_ICD9_&i le "804.99" %then EMS_TC_ICD9_grp&i=1;
1937 %else %if "805.00" le EMS_TC_ICD9_&i le "809.99" %then EMS_TC_ICD9_grp&i=2;
1938 %else %if "810.00" le EMS_TC_ICD9_&i le "819.99" %then EMS_TC_ICD9_grp&i=3;
1939 %end;
1940
1941 %put EMS_TC_ICD9_grp&i icdf.;
1942 run;
1943 %end;
1944
1945 %MEND ICD9;
1946 %ICD9(4, EMS_TC_ICD9_, EMS_TC_ICD9_grp);
MPRINT(ICD9): DATA TC_viaEMS_cleaning1;
MPRINT(ICD9): SET TC_viaEMS_cleaning;
EMS_TC_ICD9_grp1 icdf.
MPRINT(ICD9): run;
NOTE: There were 8921 observations read from the data set WORK.TC_VIAEMS_CLEANING.
NOTE: The data set WORK.TC_VIAEMS_CLEANING1 has 8921 observations and 49 variables.
NOTE: DATA statement used (Total process time):
real time 0.03 seconds
cpu time 0.06 seconds
EMS_TC_ICD9_grp2 icdf.
MPRINT(ICD9): run;
EMS_TC_ICD9_grp3 icdf.
MPRINT(ICD9): run;
EMS_TC_ICD9_grp4 icdf.
MPRINT(ICD9): run;
Use an array not a macro.
Or a format.
http://www.ats.ucla.edu/stat/sas/seminars/SAS_arrays/default_new.htm#new_vars
Use an array not a macro.
Or a format.
http://www.ats.ucla.edu/stat/sas/seminars/SAS_arrays/default_new.htm#new_vars
Thanks Reeza, it worked perfectly! Great reference document for arrays!
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.