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

📢

ANNOUNCEMENT

The early bird rate has been extended! Register by March 18 for just $695 - $100 off the standard rate.

 

Check out the agenda and get ready for a jam-packed event featuring workshops, super demos, breakout sessions, roundtables, inspiring keynotes and incredible networking events. 

 

Register now!

From SAS Users blog
Want more? Visit our blog for more articles like these.
5 Steps to Your First Analytics Project Using SAS

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.

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