Hi Sas user,
I am trying to assign prescription variables as 1 in this code
data cdmeds;
set ndc2;
if NONPROPRIETARYNAME = 'Metronidazole' or 'infliximab' or 'natalizumab' then do;
metron=1;
inflix=1;
natal=1;
end;
proc print data=cdmeds;
var natal inflix metron;
run;
However, my log appears like this with all missing values (see attachment). What am I doing wrong?
Hi @nturne
Maybe try this (it seems more logical according to the variables names but I am not sure as I can't see your raw data)
data cdmeds;
set ndc2;
if lowcase(NONPROPRIETARYNAME)='metronidazole' then metron=1;
else if lowcase(NONPROPRIETARYNAME)='infliximab' then inflix=1;
else if lowcase(NONPROPRIETARYNAME)='natalizumab' then natal=1;
run;
proc print data=cdmeds;
var metron inflix natal;
run;
Best,
I think this is the syntax you're looking for
data cdmeds;
set ndc2;
if NONPROPRIETARYNAME in ('Metronidazole', 'infliximab', 'natalizumab') then do;
metron=1;
inflix=1;
natal=1;
end;
run;
proc print data=cdmeds;
var natal inflix metron;
run;
Thank you for your suggestion, but it still did not work.
I can't see your data or your log. Only your code 🙂
Please post your log.
see picture below!
This is your result data, not your log. Please don't make us guess the structure of your data.
NOTE: There were 193176 observations read from the data set WORK.CDMEDS.
NOTE: PROCEDURE PRINT used (Total process time):
real time 0.47 seconds
cpu time 0.48 seconds
180 data cdmeds;
181 set ndc2;
182 if NONPROPRIETARYNAME in ('metronidazole', 'infliximab' , 'natalizumab') then do;
183 metron=1;
184 inflix=1;
185 natal=1;
186 end;
187 run;
NOTE: There were 193176 observations read from the data set WORK.NDC2.
NOTE: The data set WORK.CDMEDS has 193176 observations and 29 variables.
NOTE: DATA statement used (Total process time):
real time 0.34 seconds
cpu time 0.32 seconds
188
189 proc print data=cdmeds;
190 var metron natal inflix;
191 run;
NOTE: There were 193176 observations read from the data set WORK.CDMEDS.
NOTE: PROCEDURE PRINT used (Total process time):
real time 0.57 seconds
cpu time 0.57 seconds
192 ***Re
193 data cdmeds;
194 set ndc2;
195
196 if lowcase(NONPROPRIETARYNAME) = 'metronidazole' then metron=1;
197 else if lowcase(NONPROPRIETARYNAME) = 'infliximab' then inflix=1;
198 else if lowcase(NONPROPRIETARYNAME) = 'natalizumab' then natal=1;
199
NOTE: There were 193176 observations read from the data set WORK.NDC2.
NOTE: The data set WORK.CDMEDS has 193176 observations and 29 variables.
NOTE: DATA statement used (Total process time):
real time 0.37 seconds
cpu time 0.36 seconds
200 proc print data=cdmeds;
201 var natal inflix metron;
202 run;
This is my log. Although, there is no error message, I still do not have any values in my output.
Add this into your case statement.
else delete;
It could be that your proc print isn't printing enough observations to view a hit. This will show you for sure that something (or nothing) is being identified.
-unison
Add nonproprietaryname to your var list in proc print, to check it.
@nturne wrote:
Thank you for your suggestion, but it still did not work.
Please don't feed us the proverbial "blonde secretary" quotes.
Post the LOG (using the {I} button), and post example data as a data step with datalines. DO NOT post pictures of data, we're not hired as your typists.
I apologize if i offended the SAS experts. I am new to sas communities so I'm still learning how to use this. I had no idea we could not take screen shots (note to self).
Hi @nturne
Maybe try this (it seems more logical according to the variables names but I am not sure as I can't see your raw data)
data cdmeds;
set ndc2;
if lowcase(NONPROPRIETARYNAME)='metronidazole' then metron=1;
else if lowcase(NONPROPRIETARYNAME)='infliximab' then inflix=1;
else if lowcase(NONPROPRIETARYNAME)='natalizumab' then natal=1;
run;
proc print data=cdmeds;
var metron inflix natal;
run;
Best,
The same using an array an more practical if you have a long list of drugs:
data cdmeds;
set ndc2;
array presc(3) $20 ('metronidazole','infliximab','natalizumab'); /* specify the list of drugs */
array flag(3) metron inflix natal; /* specify the list of associated flags in the same order */
do i=1 to dim(presc);
if index(lowcase(nonproprietaryname),presc(i))>0 then do;
flag(i)=1;
leave;
end;
end;
drop i;
run;
proc print data=cdmeds;
var metron inflix natal;
run;
Hi,
I received the following error:
361 do i=1 to dim(presc);
362 if index(nonproprietaryname),presc(i))>0 then do;
- -
22 22
200 200
-----
71
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, *, **, +, -, /, ;, <, <=,
<>, =, >, ><, >=, AND, EQ, GE, GT, IN, LE, LT, MAX, MIN, NE, NG, NL, NOT, NOTIN,
OR, THEN, ^, ^=, |, ||, ~, ~=.
ERROR 200-322: The symbol is not recognized and will be ignored.
ERROR 71-185: The INDEX function call does not have enough arguments.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.