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
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;
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.
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...
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;
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
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".
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+"
;
N comes before Y so the default order works and didn't need the prefacing 1 and 2.
Linlin,
If you dont mind could you also help me interpret the code for the other question I posted today.
Regards
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+"
;
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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.