BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Cassie2
Calcite | Level 5

Hi all,

 

I'm having some trouble dealing with my data set. First my orginal data FREQ looks like this:

 

Capture.PNG

 

I want to clean the data set and turned them into number so I write these codes: 

 

data hth1n18.data;
set hth1n18.data;
If Qu_11 = 'Very Low' then Qu_11=1;
If Qu_11 = 'Ver Low' then Qu_11=1;
If Qu_11 = 'Very Low  ' then Qu_11 = 1;
If Qu_11 = 'Low' then Qu_11 = 2;
If Qu_11 = 'Medium' then Qu_11 =3;
If Qu_11 = 'Meduim' then Qu_11 = 3;
If Qu_11 = 'High' then Qu_11 =4;
If Qu_11 = 'Very High' then Qu_11 = 5;
run;

 

Now my FREQ looks like this, I have duplicate value in the FREQ table. Also I cannot run the proc means for this variable. 

 

Capture.PNG

Proc means show the following error: 

 

103 Proc Means data=hth1n18.data Maxdec=2 Mean Median Min Max;
104 var Qu_11;
ERROR: Variable Qu_11 in list does not match type prescribed for this list.
105 run;

 

Please help! Thanks a lot 😄 😄 

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

This happens because Qu_11 is a character variable and you try to use it in a numeric context. Use some other variable name for you numeric representations and use that in your analysis.

View solution in original post

4 REPLIES 4
PeterClemmensen
Tourmaline | Level 20

This happens because Qu_11 is a character variable and you try to use it in a numeric context. Use some other variable name for you numeric representations and use that in your analysis.

Cassie2
Calcite | Level 5

Thank you!

Tom
Super User Tom
Super User

You cannot change the type for a variable once it is set. So SAS will convert the numbers to strings to store them into the character variable. That is why the numbers in your second PROC FREQ are right aligned instead of left aligned.

 

You cannot take mean of a string.

 

Make a new variable.

Note that trailing spaces are meaningless to SAS. More likely one of the Very Low values has leading spaces instead.

If left(Qu_11) = 'Very Low' then Qu_11_num = 1;

 

Cassie2
Calcite | Level 5

It worked thank you very much

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 25. 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
  • 4 replies
  • 885 views
  • 0 likes
  • 3 in conversation