DATA Step, Macro, Functions and more

Issue while creating 0 /1 variable from categorical variable

Accepted Solution Solved
Reply
New User
Posts: 1
Accepted Solution

Issue while creating 0 /1 variable from categorical variable

Hi ,

 
I am facing the below problem while creating the dummy variable for the variable age_restriction
 
1- The variable is a character variable and contains 9 records (3,4,34,35,45,3U,4U and 5U)....
2-when i try to create the dummy variable it does not take the 3 as character variable and assumes it as numeric variable.
 
3- The code which i use for creating dummy variable is  below 
if age_restriction='3' then Age_R1=1;  else Age_R1=0;
 
i always get the value of Age_R1  =0 even though if age_restriction contains 3 as its value .
 
 
 
 
can you please help me on this error 

Accepted Solutions
Solution
‎01-15-2016 08:59 AM
Super User
Posts: 6,932

Re: Issue while creating 0 /1 variable from categorical variable

You most probably have an alignment problem (the '3' is not the first character in age_restriction).

Use the left() function to left-align the variable before checking for its contents.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers

View solution in original post


All Replies
Solution
‎01-15-2016 08:59 AM
Super User
Posts: 6,932

Re: Issue while creating 0 /1 variable from categorical variable

You most probably have an alignment problem (the '3' is not the first character in age_restriction).

Use the left() function to left-align the variable before checking for its contents.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 1 reply
  • 156 views
  • 0 likes
  • 2 in conversation