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

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

1 ACCEPTED SOLUTION

Accepted Solutions
Jagadishkatam
Amethyst | Level 16

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;
Thanks,
Jag

View solution in original post

8 REPLIES 8
Jagadishkatam
Amethyst | Level 16

I don't see any difference between the a (data with input statement) and want dataset. Could you please elaborate your question

Thanks,
Jag
kiranv_
Rhodochrosite | Level 12

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;

art297
Opal | Level 21

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

Jagadishkatam
Amethyst | Level 16

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;

Thanks,
Jag
Astounding
PROC Star

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.

sanjay1
Obsidian | Level 7

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.

Jagadishkatam
Amethyst | Level 16

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;
Thanks,
Jag
sanjay1
Obsidian | Level 7

Thank you jagadish, it works well for me.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 8 replies
  • 1256 views
  • 1 like
  • 5 in conversation