Hi SAS Experts,
I want to retain the observations of a data set with the corresponding values. Below is the dataset.
data a;
input div$ marks;
datalines;
middle 88
low 55
end 35
start 99
;
run;
I want the output like this.
div marks
start 99
middle 88
low 55
end 35
Please help
Thanks & Regards,
Sanjay
it would be good to create an ord variable using informat and sort data like below
data a;
input element$ score;
datalines;
end 800
middle 1000
start 700
Low 600
;
run;
proc format;
invalue ord
'start'=1
'middle'=2
'Low'=3
'end'=4;
run;
data b;
set a;
ord=input(element,ord.);
run;
proc sort data=b;
by ord;
run;
I don't see any difference between the a (data with input statement) and want dataset. Could you please elaborate your question
this needs an order by statement. I am not sure what you are looking for. It is missing peoper order which is there in @art297 code
proc sql;
select * from a
order by marks;
quit;
Are you only trying to reorder the data in descending order according to the values of marks?
data a; input div$ marks; datalines; middle 88 low 55 end 35 start 99 ; run;
proc sql; create table want as select * from a order by marks descending ; quit;
Art, CEO, AnalystFinder.com
If you want to order the data like what @kiranv_ mentioned then you could try proc sort like below
proc sort data=a out=want;
by descending marks;
run;
Maybe. Or maybe it should be sorted like this:
proc sort data=a out=want;
by descending div;
run;
It's really up to the poster to tell us what "like this" means instead of relying on us to guess.
Hi Astounding,
Sorry for the confusion, below is the example data set.
data a;
input element$ score;
datalines;
end 800
middle 1000
start 700
Low 600
;
run;
desired output:
Start 700
middle 1000
low 600
end 800
Actually am trying to draw a waterfall chart which starts from Start,middle,low and end.
it would be good to create an ord variable using informat and sort data like below
data a;
input element$ score;
datalines;
end 800
middle 1000
start 700
Low 600
;
run;
proc format;
invalue ord
'start'=1
'middle'=2
'Low'=3
'end'=4;
run;
data b;
set a;
ord=input(element,ord.);
run;
proc sort data=b;
by ord;
run;
Thank you jagadish, it works well for me.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.