BookmarkSubscribeRSS Feed
manya92
Fluorite | Level 6

%macro demo;
%let ccnames=Myocardial infarction*Congestive heart failure*Peripheral vascular disease*Cerebrovascular disease*Dementia*Chronic pulmonary disease*Rheumatic disease*Peptic ulcer disease*Mild liver disease*Diabetes without chronic complication*Diabetes with chronic complication*Hemiplegia or paraplegia*Renal disease*Any malignancy*Moderate or severe liver disease*Metastatic solid tumor*AIDS/HIV;
%let cc1 = %str('I21','I22','I252','410','412');
%let cc2 = %str('I099','I110','I130','I132','I255','I420','I425','I426','I427','I428','I429','I43','I50','P290','39891','40201','40211','40291','40401','40403','40411','40413','40491','40493','4254','4255','4256','4257','4258','4259','428');
%let cc3 = %str('I70','I71','I731','I738','I739','I771','I790','I792','K551','K558','K559','Z958','Z959','0930','4373','440','441','4431','4432','4433','4434','4435','4436','4437','4438','4439','4471','5571','5579','V434');
%do i=1 %to 17;
%let ccname=%scan(&ccnames., &i., *);
proc sql;
create table _15_cohort_cc&i. as
select distinct enrolid, "&ccname." AS cc&i.
from derived._15_diagtable a inner join derived._15_firstproc b
on a.enrolid=b.enrolid and a.code in: (&&cc&i.) and b.first-180<=a.svcdate<=b.first
order by enrolid;
quit;
%end;

 

what is this code doing ? i do not understand macros that well, any help is appreciated

5 REPLIES 5
RW9
Diamond | Level 26 RW9
Diamond | Level 26

It is creating a set of macro lists E.g. (and note how I am using the code window - its the {i} above post):

%let cc1 = %str('I21','I22','I252','410','412');

And then a bit of code with those lists.  

%do i=1 %to 17;
%let ccname=%scan(&ccnames., &i., *);
proc sql;
create table _15_cohort_cc&i. as
select distinct enrolid, "&ccname." AS cc&i.

This is basically looping over each of the ccnames. list and creating a dataset for each one.

My opinion is this is a very bad coding and data modelling setup, and I personally would delete it.  

Put data in datasets then work with Base SAS - which is the programming language - to manipulate the data.  This is how programming should work.  Macros do have a use, but doing data processing and such like it is not it.

manya92
Fluorite | Level 6

If i have to look for 139 codes from 001-139 which can have sub categories , how can i achieve this by simple SAS coding ? or using %str. Also my code list includes ICD9 codes which are not in sequence , for Eg. 

254.1, 255.8, 323.x etc.

 

and i want to look for both 001-139 and the second list of random not sequenced codes using simple SAS coding ?

 

manya92
Fluorite | Level 6

This is the exclusion crtieria 

  1. Any patient who had a serious or opportunistic infection within 30 days prior to the index date.

    1.1 Infections resulting in hospitalization: any disease/condition listed in the final outcome definition that was coded in any of the 15 diagnosis fields of an inpatient admission claim.

     

    Or

     

    Infections resulting in administration of intravenous antibiotics: any disease/condition listed in the final outcome definition that was coded in any of the 9 diagnosis fields of an outpatient services claim and which was treated with an intravenous antibiotic as defined by specific Healthcare Common Procedure Coding System code or a National Drug code. Intravenous antibiotic therapy could not be more than 7 days before or 7 days after the infection diagnosis.

     

  2. 001

     

    002

     

    003

     

    004

     

    005

     

    006

     

    007

     

    008

     

    009

     

    010-018 Tuberculosis* 

    010

     

    011

     

    012

     

    013

     

    014

     

    015

     

    016

     

    017

     

    018

     

    020-027 Zoonotic bacterial diseases 

    020

     

    021

     

    022

     

    023

     

    024

     

    025

     

    026

     

    027

     

    030-041 Other bacterial diseases 

    030

     

    031

     

    032

     

    033

     

    034

     

    035

     

    036

     

    037

     

    038

     

    039

     

    040

     

    041

     

    042 Human Immunodeficiency Virus

    042

     

    045-049 Poliomyelitis/other non-arthropod viral diseases of CNS* 

    045

     

    046

     

    047

     

    048

     

    049

     

    050-057 Viral diseases accompanied by exanthem 

    050

     

    051

     

    052

     

    053

     

    054

     

    055

     

    056

     

    057

     

    060-066 Arthropod-borne viral diseases 

    060

     

    061

     

    062

     

    063

     

    064

     

    065

     

    066

     

    070-079 Other diseases due to viruses & chlamydiae 

    070

     

    071

     

    072

     

    073

     

    074

     

    075

     

    076

     

    077

     

    078

     

    079

     

    080-088 Rickettsioses & other arthropod-borne diseases 

    080

     

    081

     

    082

     

    083

     

    084

     

    085

     

    086

     

    087

     

    088

     

    090-099 Syphilis & other venereal diseases* 

    090

     

    091

     

    092

     

    093

     

    094

     

    095

     

    096

     

    097

     

    098

     

    099

     

    100-104 Other spirochetal diseases 

    100

     

    101

     

    102

     

    103

     

    104

     

    110-118 Mycoses* 

     

    110

     

    111

     

    112

     

    114

     

    115

     

    116

     

    117

     

    118

     

    120-129 Helminthiases 

    120

     

    121

     

    122

     

    123

     

    124

     

    125

     

    126

     

    127

     

    128

     

    129

     

    130-136 Other infectious & parasitic diseases 

    130

     

    131

     

    132

     

    133

     

    134

     

    135

     

    136

     

    137-139 Late effects of infectious & parasitic diseases 

    137

     

    138

     

    139

     

 

254.1

255.8

323.x

324.x

357.0

380.1

382.0

382.9

383.x

384.0

384.1

421.x

422.x

424.9

447.2

457.2

460

461.x

462

463

464.x

465.x

466.x

472

473.x

474.0

475

476.x

480

481

482

483

484

485

486

487.1

487.8

490

491.2

510.x

511.1

513.x

519.1

519.2

522.5

522.7

523.3

528.3

528.5

529.0

540-542

550.0

551.x

566

567.x

569.5

572

572.0

572.1

574.0

574.1

574.3

574.4

575.0

575.1

576.1

590.x

595.x

597.0

597.8

599.0

603.1

604.x

607.1

607.2

614.x

615.0

615.9

616.x

680.x

681.x

682.x

684

685.0

686.x

711.0

711.9

728.0

729.4

730.x

785.4

788.7

790.7

790.8

996.6

998.5

999.3

 

I need to look for all these codes as they are the for infection conditions requiring hospitalization or IV antibiotics.

 

how can i do this ?

 

I have my cohort with one row per patient called cohort1

RW9
Diamond | Level 26 RW9
Diamond | Level 26

I have given you the code on your other post.  First, you create a dataset of the data - this being the codes from the exclusion criteri - often people like to put these into a spreadsheet and read that in.  But you can do it in a datastep:

data codes;
  input code $;
datalines;
001
002
003
004
005
006
007
008
;
run;

Next we uitilise that code to find out from a dataset demo, which of those pt's have this code:

proc sql;
  create table exclusion_pts as
  select pt
  from   demo 
  where  code in (select code from codes);
quit;

Very simple Base SAS, with data all in datasets with formats and such like and all the Base SAS functionality available to process it.  You could even improve on this to expand the list of codes automatically, maybe:

data codes (drop=i);
  input code $;
if index(code,"-") then do;
do i=input(scan(code,1,"-"),best.) to input(scan(code,2,"-"),best.);
code=put(i,z3.);
output;
end;
end; datalines; 001-007 ; run;

The above does the ones with a hyphen in for example.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 522 views
  • 2 likes
  • 3 in conversation