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

Hi!

 

I have a value of string variable :

 

AESOUT

3::4  (this is the value of variable AESOUT)

 

I need other variables to populate with 'Y' if contains a 3 or a 4 

 

data want;

set have;

 

if findw(aesout,'3')>0 then AESHOSP='Y';
else AESHOSP='';

if findw(aesout,'4')>0 then AESDISAB='Y';
else AESDISAB='';

 

...However I am getting null values in the new variables (AESHOSP and AESDISAB) where I am expecting a 'Y'.  

 

Help is appreciated!

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

try index

data h;
s="3::4";
if index(s,'3')>0 then new_var='yes';
if index(s,'4')>0 then new_var1='yes';
run;

View solution in original post

2 REPLIES 2
novinosrin
Tourmaline | Level 20

try index

data h;
s="3::4";
if index(s,'3')>0 then new_var='yes';
if index(s,'4')>0 then new_var1='yes';
run;

ballardw
Super User

There are some very good reasons to code Yes/no as numeric 1/0 values.

One is that when asking to compare if value='Y' you might have set some values to lower case y or even spelled it out 'yes' or 'Yes' depending. And then you get into a look at data to check the values.

 

Second you can always have a custom format to display Yes/No, Y/N, T/F, True/False, Member/Not member or any pair of values without having to change the variable coding.

 

Third in summary and report procedures a SUM of the variable will give you count of Yes values and Mean is a percent of Yes values. This may not sound like much but generate a table with Number of Yes and Percent Yes that match your expectations with 'Yes' valued variables.

 

Fourth some modeling procedures may require a numeric variable.

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
  • 650 views
  • 0 likes
  • 3 in conversation