Help using Base SAS procedures

Formats error

Accepted Solution Solved
Reply
Super Contributor
Posts: 1,040
Accepted Solution

Formats error


Hi Team,
I learnt a couple of days ago from the Forum about getting the outputs in the order of the format applied and not alphabetically which is usually the case

.(by using numbers in the front as shown)

proc format;

VALUE $Bikes

"N"="1-Suzuki-"

"Y"="2-Suzuki+"

"F"="3-Foam"

;

I am getting the output as :

3-Foam

1-Suzuki-

2-Suzuki+

Why is the 3 coming at the first place?????????

Could anyone help me solve this problem please


Accepted Solutions
Solution
‎09-24-2012 11:27 AM
Super Contributor
Posts: 1,636

Re: Formats error

example:

proc format;

VALUE $Bikes

"N"="1-Suzuki-"

"Y"="2-Suzuki+"

"F"="3-Foam";

data have;

input bike $ @@;

cards;

Y N Y F F Y N

;

proc freq data=have order=formatted;

   tables bike;

   format bike $bikes.;

  run;

View solution in original post


All Replies
Super User
Posts: 10,538

Re: Formats error

Which procedure are using and what options? For example Proc tabulate has order= options of formatted, data, freq and unformatted as options which can also be affected by using class options of ascending, descending or groupinternal.

Super Contributor
Posts: 1,040

Re: Formats error

Thanks for the reply...

First I wrote a format.

Then I applied it in the datastep for example:

data want;

set have;

format var $BIKES.;

run;

Later I  am using the HAVE dataset in the Proc freq with ODS option to get a Pdf.

But I was thinking irrespective of the procedure I use since I put 1,2 and 3. I should get it in that order...

Solution
‎09-24-2012 11:27 AM
Super Contributor
Posts: 1,636

Re: Formats error

example:

proc format;

VALUE $Bikes

"N"="1-Suzuki-"

"Y"="2-Suzuki+"

"F"="3-Foam";

data have;

input bike $ @@;

cards;

Y N Y F F Y N

;

proc freq data=have order=formatted;

   tables bike;

   format bike $bikes.;

  run;

Super Contributor
Posts: 1,040

Re: Formats error

Thanks Linlin,

This code works. But do I have to use the format stmnt only in the freq step? cant i use in the datastep and get the job done?

Regards

Super User
Posts: 10,538

Re: Formats error

Data step repeats the order the data is read as it processes one record at a time (generally) when using the set statement or reading an external file.

However the format doesn't need to be added as you did. Notice that Linlin's solution does not use your set "want".

Super Contributor
Posts: 1,040

Re: Formats error

Why I am asking that question is that:

fOR FORMAT LIKE THIS IT WORKED PERFECT. i MEAN 1 COMES BEFORE 2.

wITH THE EARLIER EXAMPLE( WITH 1 2 AND 3)  IT WORKS WIRED

VALUE $COBRA

"N"="1- COB-"

"Y"="2- COB+"

;

Super User
Posts: 10,538

Re: Formats error

N comes before Y so the default order works and didn't need the prefacing 1 and 2.

Super Contributor
Posts: 1,040

Re: Formats error

Linlin,

If you dont mind could you also help me interpret the code for the other question I posted today.

Regards

Super Contributor
Posts: 1,040

Re: Formats error

ALSO:

If there are 20 variables like shown (few) below do I need to keep on doing what I did or is there any short cut method to do this??????

$DIA to be applied on DIA variable

$COBRA to be applied on COBRA variable.so on

VALUE $DIA

"N"="1- Dia-"

"Y"="2- Dia+"

;

VALUE $COBRA

"N"="1- COB-"

"Y"="2- COB+"

;

VALUE $CAB

"N"="1- Cabr-"

"Y"="2- Cab+"

;

VALUE $HITECH

"N"="1- Hit-"

"Y"="2- Hit+"

;

VALUE $PULL

"N"="1- Pull-"

"Y"="2- Pull+"

;


Super User
Posts: 10,538

Re: Formats error

Again, the "N" will come before "Y" so the prefaces won't be needed unless you are going to force output to use the formatted option.

Ordering output sometimes is something to consider when creating coding schemes.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 10 replies
  • 295 views
  • 9 likes
  • 3 in conversation