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

A while back a responder generously provided to me a detailed example on writing a proc format statement. I'm now trying to use that example and do something useful. Here's what i have.

proc format;

value couse2 0='0 neither' 1='1 either' 2 '2 both';

value dalc1r_ 0= '0 no' 1='1 yes';
value dmj1r_ 0 = '0 no' 1 = '1 yes';
run;

proc freq data=co_usevars;

table couse2;

table dalc1r*dmj1r;
run;

Here's what i want. Instead of the standard listing, I want to see the frequency listings show this;

0 neither 200   25.00   200   25.00

1 either 400  50.00  600  75.00

2 both 200  25.00  800  100.00

I want the crosstab to show, what i would call the value labels, e.g., 1 yes, in the table.

Nothing works.

The format for couse2 gives an error because a variable can not end in a number, dalc1r_ doesn't give an error in the format command but neither that construction nor dalc1r yields the value labels in either the frequency listing nor the crosstab.You may be wondering why i wrote dalc1r 0='0 no' instead of dalc1r 0='no'. That's because a much more experienced use warned me that the 'no' wipes out the 0. I've got Ron Cody's very nice book and, interesting ly, in the proc format chapter he does not show an example that uses proc freq. I been told that proc report or proc tabulate gives more options. I accept that it's true--and i'm sure that additional work is involved. What is useful enough to us is a fully labeled frequency listing or crosstab table, sometimes with a chisquare and sometimes without a chisquare.

The question is can sas be made to give me what i want?

 

Thanks, Gene Maguin

 

 

 

 

 

 

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

The error for proc format about not allowing numerals at the end of the format name makes a lot of sense because you use the digits at the end of a format to specify how many characters to display in the output.

So rename your Couse2 format Couse or end the name with a non-numeric character like _.

proc format;
value couse 0='0 neither' 1='1 either' 2 = '2 both';

value dalc1r_ 0= '0 no' 1='1 yes';
value dmj1r_ 0 = '0 no' 1 = '1 yes';
run;

 

 

When a format is not the default assigned to a variable you have to associate it which your code does not show any attempt at. The Format statement in a procedure associates the format with the variables.

 

proc freq data=co_usevars;
   table couse2;
   table dalc1r*dmj1r;
   format couse2 couse. dalc1r dalc1r. dmj1r dmj1r. ;
run;

Please post a reference to your source of"That's because a much more experienced use warned me that the 'no' wipes out the 0." Formats do not "wipe out" anything. They show the value you pick. If you need the 0 then fine, show it. But the "no" does not wipe out anything it just displays.

 

For future reference, please post the code you submitted from the Log and paste into a code box opened with the </> icon. And include any warnings or notes. Since your posted code for the first format has an error , no equal sign for the value 2, there could be other things going on that the log will tell use and does show the exact code submitted.

View solution in original post

1 REPLY 1
ballardw
Super User

The error for proc format about not allowing numerals at the end of the format name makes a lot of sense because you use the digits at the end of a format to specify how many characters to display in the output.

So rename your Couse2 format Couse or end the name with a non-numeric character like _.

proc format;
value couse 0='0 neither' 1='1 either' 2 = '2 both';

value dalc1r_ 0= '0 no' 1='1 yes';
value dmj1r_ 0 = '0 no' 1 = '1 yes';
run;

 

 

When a format is not the default assigned to a variable you have to associate it which your code does not show any attempt at. The Format statement in a procedure associates the format with the variables.

 

proc freq data=co_usevars;
   table couse2;
   table dalc1r*dmj1r;
   format couse2 couse. dalc1r dalc1r. dmj1r dmj1r. ;
run;

Please post a reference to your source of"That's because a much more experienced use warned me that the 'no' wipes out the 0." Formats do not "wipe out" anything. They show the value you pick. If you need the 0 then fine, show it. But the "no" does not wipe out anything it just displays.

 

For future reference, please post the code you submitted from the Log and paste into a code box opened with the </> icon. And include any warnings or notes. Since your posted code for the first format has an error , no equal sign for the value 2, there could be other things going on that the log will tell use and does show the exact code submitted.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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
  • 638 views
  • 0 likes
  • 2 in conversation