BookmarkSubscribeRSS Feed
Jannie_D
Calcite | Level 5

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?

3 REPLIES 3
PaigeMiller
Diamond | Level 26

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

--
Paige Miller
data_null__
Jade | Level 19

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.

ballardw
Super User

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;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 479 views
  • 0 likes
  • 4 in conversation