DATA HAVE;
INPUT B A D C E;
CARDS;
RUN;
HERE, I WANT TO CHANGE INPUT ORDER OF VARIABLE IN ASCENDING OR DESCENDING ORDER
i.e A B C D E
My usual opinion is that re-ordering variables in a data set is pointless.
You usually only need to re-order the data sets upon output, and then PROC PRINT and PROC REPORT and most other display procedures allow you to produce results with the columns in the desired order.
Please do not type in ALL CAPITAL LETTERS.
This seems like a pointless thing to do, print results with column names in alphabetical order, except if the names have a numeric suffix, such as x1-x100. Then you could simply use x1-x100 to obtain your ordering.
Otherwise:
proc print data=mydataset;
var baboon elephant giraffe gorilla sandhillcrane snake ... ;
/* You have to type all of your variables here */
run;
If you don't want to type all of your 100 variables (a natural desire), this would work:
proc sql noprint;
select distinct names into :names separated by ' ' from sashelp.vcolumn
where libname='WORK' and memname='MYDATASETNAME';
quit;
proc print data=mydataset;
var &names;
run;
Check your keyboard, your Capslock is stuck.
What do you mean? Are you saying want to change the INPUT statement? Are you saying you want to check the order that the variables appear in the dataset to be different than they appear in the INPUT statement? Do you want to do it as part of that same step? Or as an additional step that you run after the data set is run.
@Saikiran_Mamidi wrote:
DATA HAVE;
INPUT B A D C E;
CARDS;
RUN;
HERE, I WANT TO CHANGE INPUT ORDER OF VARIABLE IN ASCENDING OR DESCENDING ORDER
i.e A B C D E
A mentioned likely not worth a lot of time.
Provide actual example data that you expect to read.
There are ways to read data other than left to right but the actual content of the values determines which of the methods is possible.
If the data is in a fixed column layout where variable B always occupies columns 1-3 and variable A always occupies columns 4-8 then column input can be used.
Your extremely limited input statement though implies list input which requires knowledge of the actual values to parse an input line. Likely involving :
An input @
A do loop
An array
Scan function
Explicit conversion from character to numeric.
If that sounds like more work than you want to maintain....
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.