I would like to sort a dataset, by the first column.
proc sort data=have;
by Col#1;
run;
Suppose I don't have the actual name of the Col#1 variable.
(Actually, I do, of course, but it varies among datasets. And I'm seeking a generic approach.)
Can this be done?
Thanks!
Nicholas Kormanik
Use SQL, as @Reeza suggested, or sort by everything (it will sort on the first variable first)
proc sql;
create table cars as select * from sashelp.cars
order by 1;
quit;
/* Or */
proc sort data=sashelp.cars out=cars; by _all_; run;
Not via PROC SORT but PROC SQL allows it.
Hi,
A couple of steps before proc sort may produce the desired output.
proc contents data=sashelp.cars order=varnum out=vars(keep=name varnum) ;
run;
proc sql;
select name into :sort_var from vars
where varnum=1;
quit;
proc sort data=cars;
by &sort_var;
run;
Use SQL, as @Reeza suggested, or sort by everything (it will sort on the first variable first)
proc sql;
create table cars as select * from sashelp.cars
order by 1;
quit;
/* Or */
proc sort data=sashelp.cars out=cars; by _all_; run;
Thank you all for your help.
Since these datasets only contain two columns, it is easiest to sort by everything. Straightforward and easy. Wonderful. Glad it can be done this way.
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.