This is my code:
data amt2.value_labels;
set amt2.assignment2;
if gender = 0 then gender = 'Male';
run;
This converted all the values with zero to .
Error Message:
You are trying to assign a character value to a numeric variable, that is why you get an error. Write the value 'Male' to a vairble suct as genderc and yo will be fine
data amt2.value_labels;
set amt2.assignment2;
if gender = 0 then genderc = 'Male';
run;
You are trying to assign a character value to a numeric variable, that is why you get an error. Write the value 'Male' to a vairble suct as genderc and yo will be fine
data amt2.value_labels;
set amt2.assignment2;
if gender = 0 then genderc = 'Male';
run;
Or skip the new variable entirely.
I am guessing that a value of 1 may be female. If different change the vale in proc format code from 1 to the appropriate value.
If you have more values for gender then add additional code values.
proc format library=work; value mygender 0= 'Male' 1= 'Female' ; proc print data=amt2.assignment2; var gender; format gender mygender.; run;
Custom formats can be used to display different text for the same variable in different places. For instance you may have a need for a display of single letter for gender, so you make a different named format (the first word after VALUE above) and only have M and F as values, or you want to display something like "** Male **", a different format and use. Groups of codes can also be assigned to single
display value that will be honored by most procedures.
Especially with large data sets creating a new format may be much more time efficient than duplicating a data set just to get a different display.
And you can use formats for character variables in a similar way.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.