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!
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.