DATA Step, Macro, Functions and more

Create multiple character macro variables using conditional processing

Accepted Solution Solved
Reply
Contributor
Posts: 25
Accepted Solution

Create multiple character macro variables using conditional processing

Hi All,

I have a reference table like this:

ICD9      Suicide        Depression     Homicide     Anxiety

290         0                 0                      0                   0

291         0                 0                      0                   0

292         0                 0                      0                   0

V171       0                 0                      0                   0

294         0                 0                      0                   0

V143      0                 1                      0                   0

296         0                 0                      0                   0

296         0                 0                      0                   1

........

Now I want to create five macro variables.-----&ICD, &Suicide, &Depression, &Homicide, &Anxiety, and use values under ICD9 to populate these macro variables.

The logic is like this (the codes are probably not correct):

call symput ('ICD', ICD9);

if Suicide=1 then call symput ('Suicide', ICD9);

if Depression=1 then call symput ('Depression', ICD9);

if Homicide=1 then call symput ('Homicide', ICD9);

if Anxiety=1 then call symput ('Anxiety', ICD9);

Then I want to use medical claim table to flag those claim lines with ICD9 codes for those four conditions.

Something like this:

Data claim_output;

set claim_input;

where ICD9 in (&Suicide);

run;

What should be the correct codes for the whole process?

I appreciate any input!!

Cindy


Accepted Solutions
Solution
‎01-14-2014 03:28 PM
Super User
Posts: 19,769

Re: Create multiple character macro variables using conditional processing

Posted in reply to cindyforest7

If your data isn't massive over tens of millions I'd probably use a SQL subquery instead:

proc sql;

     create table claim_output as

     select * from claim_input

     where icd9 in (select distinct icd9 from ref where suicide=1);

quit;

View solution in original post


All Replies
Solution
‎01-14-2014 03:28 PM
Super User
Posts: 19,769

Re: Create multiple character macro variables using conditional processing

Posted in reply to cindyforest7

If your data isn't massive over tens of millions I'd probably use a SQL subquery instead:

proc sql;

     create table claim_output as

     select * from claim_input

     where icd9 in (select distinct icd9 from ref where suicide=1);

quit;

Contributor
Posts: 25

Re: Create multiple character macro variables using conditional processing

Posted in reply to cindyforest7

Thank you Reeza!

Just curious, if I want to use macro variables to do this, what the codes look like?

Thanks again!

Super User
Posts: 19,769

Re: Create multiple character macro variables using conditional processing

Posted in reply to cindyforest7

Still using a proc sql step to create your macro variables such that it completes your SAS code properly. Because they're strings they also need to have the correct quotes and commas are optional. Ie you want suicide to resolve to "V143", "128".


This is an example below:


       Proc SQL noprint;
         select quote(strip(icd9)) into :suicide separated by ','
          from reference_table

          where suicide=1;
          quit;
           run;
        %put NOTE: Suicide=&suicide;

🔒 This topic is solved and locked.

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

Discussion stats
  • 3 replies
  • 198 views
  • 3 likes
  • 2 in conversation