Recoding Variables

Reply
New Contributor
Posts: 2

Recoding Variables

Hi,

 

I'm having trouble programming new variables. This is my partial code:

 

DATA newvardata3;
SET newvardata;
           KEEP DRUGTYP1 SENTTOT0 LOGSENT REAS1 DISTRICT MONCIRC FTRACK CRIMHIST
                     YEARS CITIZEN NEWCIT NEWEDUC MONSEX NEWRACE OFFTYPE2 MONDRUG
                     CHEMTYPE SCHEDULE;
SCHEDULE = .;
             IF (DRUGTYP1=Heroin) OR (DRUGTYP1=Marijuana) OR (DRUGTYP1=LSD) OR (DRUGTYP1=MDMA / ecstasy)
             OR (DRUGTYP1=Methcathinone) OR (DRUGTYP1=Gamm-hydroxybutyric acid) THEN SCHEDULE=I;
RUN;

 

 

It's fine until I add in the last bit -- "OR (DRUGTYP1=Gamm-hydroxybutyric acid)"  - After that it gives me the error code:

 

NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.NEWVARDATA3 may be incomplete. When this step was stopped there were
0 observations and 16 variables.
WARNING: Data set WORK.NEWVARDATA3 was not replaced because this step was stopped

 

Not sure what's wrong or how I can fix it; I'm using USSC data so I didn't set the level names, nor can I change them. Any way to get around this in the code?

Super User
Posts: 17,867

Re: Recoding Variables

You have issues beside the OR. You may want to include parentheses to make sure the order of operations is what you expect.

If your doing string comparisons you need to include the strings with quotation marks.

Ie Drugtyp1 = "Heroin"

Note the comparison is case sensitive and if your checking multiple values you can use IN

If drugtyp1 in ('value1' 'value2' ...) then ..
New Contributor
Posts: 2

Re: Recoding Variables

Thank you, the quotations worked!

Super User
Posts: 17,867

Re: Recoding Variables

Please mark question as answered.
Super User
Super User
Posts: 7,407

Re: Recoding Variables

Why not use the WHO Drug Dictionary, its a standard worldwide dictionary for coding drugs:

https://en.wikipedia.org/wiki/WHO_Drug_Dictionary

 

Ask a Question
Discussion stats
  • 4 replies
  • 316 views
  • 0 likes
  • 3 in conversation