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

I am currently trying to run a macro called PROCESS by Hayes which is used to test moderation and mediation models. However I keep running into the following errors:

 

Capture.PNG

 

It appears that the error might be due to the fact that my categorical variables are currently string values (words such as "yes" or "no"). When I change the values of these variables to numbers (0 and 1) manually in excel the macro works fine. However, I get the same error when I try to recode the values of the variables in SAS using the subset command. My subsetting code looks like this:

 

Capture2.PNG

 

I would expect that my subsetting code should have the same effect as manually changing the values in excel before importing the data into SAS; however, it appears that SAS is treating them differently. If you have any advice on how I can recode my variables in SAS and have them work the macro I am using I would appreciate the help.

 

Thanks for the help.

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

When running a SAS program, you have to read the log.  There are messages that you ignored about numeric to character conversion.  What happens ...

 

You can't change a variable from being character to being numeric.  Once it's character, it remains character.  You can jump through the right hoops to get around that:

 

data subset;
   set study;
   if scarce = 'yes' then sc = 1;
   if scarce = 'no' then sc = 0;
   if purchase = 'yes' then pu = 1;
   if purchase = 'no' then pu = 0;
   drop scarce purchase;
   rename sc = scarce pu = purchase;
run;

 

This program in effect gives you new numeric variables.  You can then use DROP and RENAME to keep them under the original names, as numeric.  This version of the data should work. 

View solution in original post

1 REPLY 1
Astounding
PROC Star

When running a SAS program, you have to read the log.  There are messages that you ignored about numeric to character conversion.  What happens ...

 

You can't change a variable from being character to being numeric.  Once it's character, it remains character.  You can jump through the right hoops to get around that:

 

data subset;
   set study;
   if scarce = 'yes' then sc = 1;
   if scarce = 'no' then sc = 0;
   if purchase = 'yes' then pu = 1;
   if purchase = 'no' then pu = 0;
   drop scarce purchase;
   rename sc = scarce pu = purchase;
run;

 

This program in effect gives you new numeric variables.  You can then use DROP and RENAME to keep them under the original names, as numeric.  This version of the data should work. 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 1 reply
  • 394 views
  • 1 like
  • 2 in conversation