Hi. I'm trying to redefine some variables as number because I need a score in the end. (SF36 in Danish)
However my code does not work and i can not figure out what I am doing wrong:
this is the code
DATA sf36i;
format general_health 8.;
length general_health 8;
set SF36;
if hvordan_synes_du_dit_helbr="Fremragende" then general_health=1;
if hvordan_synes_du_dit_helbr="Vældigt godt" then general_health=2;
if hvordan_synes_du_dit_helbr="Godt" then general_health=3;
if hvordan_synes_du_dit_helbr="Mindre godt" then general_health=4;
if hvordan_synes_du_dit_helbr="Dårligt" then general_health=5;
run;
It creats number only where there is missing data and only 5. Can you help me troubleshooting?
When there are errors in the log, you need to show us the ENTIRE log (not just the errors) for this data step.
It would seem from the error message you have provided that the variable HVORDAN_SYNES_DU_DIT_HELBR is numeric and therefore you cannot test to see if it is equal to a character string such as "Fremragende". Thus it would also help if you showed us a portion of the data in data set SF36, as working SAS data step code, which you can see examples and instructions here.
Typically, we do not want the errors in the log to be used as the subject line. We would want a verbal description of the problem, such as "Trying to assign categories".
What is the data type of "hvordan_synes_du_dit_helbr" I suspect it it NUMERIC and the reason you are getting the message. SAS is trying to convert the character constant "Fremragende" to numeric for the comparison to numeric variable hvordan_synes_du_dit_helbr.
There is chance that your variable hvordan_synes_du_dit_helbr is numeric and has a custom format assigned that displays text like "Fremragende" as the formatted value.
Check to see what the Format for the variable is with Proc Contents or examining variable properties in your preferred manner.
The good news may be that you don't need a new variable at all depending on the underlying numeric range for hvordan_synes_du_dit_helbr .
You may find the result from this helpful.
proc freq data=SF36; tables hvordan_synes_du_dit_helbr ; format hvordan_synes_du_dit_helbr best5. ; run;
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
For SAS newbies, this video is a great way to get started. James Harroun walks through the process using SAS Studio for SAS OnDemand for Academics, but the same steps apply to any analytics project.
Find more tutorials on the SAS Users YouTube channel.