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


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

1 ACCEPTED SOLUTION

Accepted Solutions
Linlin
Lapis Lazuli | Level 10

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

10 REPLIES 10
ballardw
Super User

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.

robertrao
Quartz | Level 8

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...

Linlin
Lapis Lazuli | Level 10

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;

robertrao
Quartz | Level 8

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

ballardw
Super User

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".

robertrao
Quartz | Level 8

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+"

;

ballardw
Super User

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

robertrao
Quartz | Level 8

Linlin,

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

Regards

robertrao
Quartz | Level 8

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+"

;


ballardw
Super User

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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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