Hello all,
I am creating a new variable in a data step. The code is below:
if hisp_not='.' then ethnicity1='';
if hisp_not='1' then ethnicity1='';
if hisp_not='0' then ethnicity1='E1';
When I run a proc print of var ethnicity1 the output has changed to "E".
It is essential for the output data to be E1 in order to import into our database.
I checked and the format is $4 so it's not a formatting issue.
Does anyone have any idea why this would happen and how to fix it?
Thank you!
If you examine the properties of the variable Ethnicity1 you will find that it has a length of one character and so cannot accept the second character. Format does not control length, only display appearance.
If the first use of a character variable is an assignment such as your Ethnicity1=''; that will set the length of the variable. You need to specify a length before use if want it to hold longer values.
length Ethnicity1 $ 2 ;
BEFORE the assignment code you are using.
If you want multiple values treated the same you can use the IN operator
if hisp_not='.' then ethnicity1=''; if hisp_not='1' then ethnicity1=''; /* can be replaced with*/ if hisp_not in ('.' '1' ) then ethnicity1='';
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: