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

I have no issues running these codes below . But it seems I didn’t create the “antibiotics_flag" variable in my data, I just have the label, so every time I will have to re-run the whole codes (I have 20 codes blocks like this). Is there a way to save the “antibiotics_flag" as a permanent variable in my datasets? 

 

data kid2012;

set Kid_2012_core;

array diagvar $ dx1-dx25;

label antibiotics_flag = "Diagnosis code for antibiotics ADE";

antibiotics_flag = 0;

do over diagvar;

      if diagvar ="76074" or "9600 "=<diagvar<= "9609 " or diagvar="E856 " or "E9300 "=<diagvar<= "E9306 " or "E9308 "=<diagvar<= "E9309 "

      or diagvar= "E9310 " or diagvar= "E9313 "

then antibiotics_flag = 1;

      end;

PROC SURVEYFREQ DATA=kid2012;

WEIGHT DISCWT;

CLUSTER HOSP_KID ;

STRATA KID_STRATUM ;

table antibiotics_flag;

run;

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
Show your log. Your KID2012 data set is not permanent but the variable antibiotics_flag should definitely exist, unless there's a bug in the code I'm missing. The log is very helpful in identifiying that though, as well as the fact that it shows the number of variables read and written so it can confirm your observations.

No idea what you mean about 20 code blocks. FYI - if you're always starting from kid_2012_core then you won't be carrying anything forward. If you're doing this for many different flags, you should just dump all the codes into a format and use that approach instead. It's a bit more work to map the codes to the disease but it'll serve you well in the long run.

If you want to carry it 'forward' use something like this instead;

data kid2012;
set kid_2012_core;
run;

data kid2012;

set Kid2012;

array diagvar $ dx1-dx25;

label antibiotics_flag = "Diagnosis code for antibiotics ADE";

antibiotics_flag = 0;

do over diagvar;

if diagvar ="76074" or "9600 "=<diagvar<= "9609 " or diagvar="E856 " or "E9300 "=<diagvar<= "E9306 " or "E9308 "=<diagvar<= "E9309 "

or diagvar= "E9310 " or diagvar= "E9313 "

then antibiotics_flag = 1;

end;

PROC SURVEYFREQ DATA=kid2012;

WEIGHT DISCWT;

CLUSTER HOSP_KID ;

STRATA KID_STRATUM ;

table antibiotics_flag;

run;

data kid2012;
set kid2012;
.....code for next block continues..


View solution in original post

1 REPLY 1
Reeza
Super User
Show your log. Your KID2012 data set is not permanent but the variable antibiotics_flag should definitely exist, unless there's a bug in the code I'm missing. The log is very helpful in identifiying that though, as well as the fact that it shows the number of variables read and written so it can confirm your observations.

No idea what you mean about 20 code blocks. FYI - if you're always starting from kid_2012_core then you won't be carrying anything forward. If you're doing this for many different flags, you should just dump all the codes into a format and use that approach instead. It's a bit more work to map the codes to the disease but it'll serve you well in the long run.

If you want to carry it 'forward' use something like this instead;

data kid2012;
set kid_2012_core;
run;

data kid2012;

set Kid2012;

array diagvar $ dx1-dx25;

label antibiotics_flag = "Diagnosis code for antibiotics ADE";

antibiotics_flag = 0;

do over diagvar;

if diagvar ="76074" or "9600 "=<diagvar<= "9609 " or diagvar="E856 " or "E9300 "=<diagvar<= "E9306 " or "E9308 "=<diagvar<= "E9309 "

or diagvar= "E9310 " or diagvar= "E9313 "

then antibiotics_flag = 1;

end;

PROC SURVEYFREQ DATA=kid2012;

WEIGHT DISCWT;

CLUSTER HOSP_KID ;

STRATA KID_STRATUM ;

table antibiotics_flag;

run;

data kid2012;
set kid2012;
.....code for next block continues..


SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 1 reply
  • 337 views
  • 1 like
  • 2 in conversation