Help using Base SAS procedures

Proc format errors

Reply
Occasional Contributor
Posts: 14

Proc format errors

For my data, I keep getting the error message ERROR: You are trying to use the character format $SEX with the numeric variable sex in data set WORK.STUDY2. I have tried formatting it in different ways but keep getting the same message, any help is appreciated.....

 

Proc format;
*formats the sex and race variable variable as in step 5;
value _sex
1='female'
2='male';
value _race
1='Asian'
2='Black'
3='Caucasian'
4='Other';
run;
Proc freq data=study2;
tables dosedate doselot site_name pt prot_amend limit sex race;
format sex $_sex. race $_race.;

run;

 

Proc freq data=study2;
tables dosedate doselot site_name pt prot_amend limit sex race;
format sex _sex. race _race.;

run;

Super User
Posts: 19,877

Re: Proc format errors

Posted in reply to zjhansen30

You have numeric formats so you do not need the $ in front of the format, that is for character formats. A format type (numeric/character) is based on the input type, in this case 1/2. 

 

You have two proc freqs in your code, the second set of code should have worked fine. If it didn't, please post the log.

The first proc freq would not have worked because of the $ sign.

 

 

 

Occasional Contributor
Posts: 14

Re: Proc format errors

Posted in reply to zjhansen30

Sorry, I was trying to show that I have used the format command both ways in the proc freq, and neither of them worked.  It gives me the same error message no matter if I use the $ symbol or not.

Super User
Posts: 19,877

Re: Proc format errors

Posted in reply to zjhansen30

Post your full code and log.

It should work, if it's not then something else is the issue.

Ask a Question
Discussion stats
  • 3 replies
  • 181 views
  • 0 likes
  • 2 in conversation