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

I have a variable which has possible values of 1Y 2Y 3Y 4Y 5Y U <missing>

I'm creating a new variable in a data step, like this:

data want;

set have;

if var1 In('3Y','4Y','5Y') then newvar=1; else if var1=. THEN newvar=.; ELSE newvar=0;

run;

My problem is that the newvar becomes missing when in fact the original value was 1Y or 2Y.  But the newvar seems to actually be correct in the instance of it being in the IN() list.

I get no errors, but I get a warning:

Limit set by ERRORS=option reached. Further errors of this type will not be printed

(makes no sense, because I'm not getting errors)

I get a note for just about every row -

Invalid numeric data, VAR1='1Y', at line xxxx column yyyy

So - what in the world am I doing wrong that allows this to partially work? It works in the first list but apparently on the ELSE I am getting this weird note.

1 ACCEPTED SOLUTION

Accepted Solutions
stat_sas
Ammonite | Level 13

Try this.

data want;

set have;

if var1 In('3Y','4Y','5Y') then newvar=1;

else if var1=' ' THEN newvar=.;

ELSE newvar=0;

run;

View solution in original post

2 REPLIES 2
stat_sas
Ammonite | Level 13

Try this.

data want;

set have;

if var1 In('3Y','4Y','5Y') then newvar=1;

else if var1=' ' THEN newvar=.;

ELSE newvar=0;

run;

JBerry
Quartz | Level 8

that worked! Thanks

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
  • 2 replies
  • 809 views
  • 0 likes
  • 2 in conversation