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

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?

 

1 ACCEPTED SOLUTION

Accepted Solutions
ed_sas_member
Meteorite | Level 14

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,

View solution in original post

16 REPLIES 16
PeterClemmensen
Tourmaline | Level 20

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;
nturne
Calcite | Level 5

Thank you for your suggestion, but it still did not work. Smiley Sad

PeterClemmensen
Tourmaline | Level 20

I can't see your data or your log. Only your code 🙂

 

Please post your log.

nturne
Calcite | Level 5

Capture.PNG

nturne
Calcite | Level 5

see picture below!

PeterClemmensen
Tourmaline | Level 20

This is your result data, not your log. Please don't make us guess the structure of your data.

nturne
Calcite | Level 5

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.

unison
Lapis Lazuli | Level 10

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

-unison
Kurt_Bremser
Super User

@nturne wrote:

Thank you for your suggestion, but it still did not work. Smiley Sad


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.

nturne
Calcite | Level 5

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). 

ed_sas_member
Meteorite | Level 14

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,

ed_sas_member
Meteorite | Level 14

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;
nturne
Calcite | Level 5

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.