Help using Base SAS procedures

How to use an Iterative Step and Format Multiple Variables Using MACRO

Accepted Solution Solved
Reply
Occasional Contributor eap
Occasional Contributor
Posts: 11
Accepted Solution

How to use an Iterative Step and Format Multiple Variables Using MACRO

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;

Accepted Solutions
Solution
‎10-26-2016 10:47 PM
Super User
Posts: 17,864

Re: How to use an Iterative Step and Format Multiple Variables Using MACRO


All Replies
Solution
‎10-26-2016 10:47 PM
Super User
Posts: 17,864

Re: How to use an Iterative Step and Format Multiple Variables Using MACRO

Use an array not a macro. 

 Or a format. 

 

 

 http://www.ats.ucla.edu/stat/sas/seminars/SAS_arrays/default_new.htm#new_vars

Occasional Contributor eap
Occasional Contributor
Posts: 11

Re: How to use an Iterative Step and Format Multiple Variables Using MACRO

Thanks Reeza, it worked perfectly!  Great reference document for arrays!

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 244 views
  • 0 likes
  • 2 in conversation