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.
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.