BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
cindyforest7
Calcite | Level 5

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

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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

3 REPLIES 3
Reeza
Super User

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;

cindyforest7
Calcite | Level 5

Thank you Reeza!

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

Thanks again!

Reeza
Super User

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;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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