BookmarkSubscribeRSS Feed
R_Win
Calcite | Level 5
hi i am haivng variables .i wan them in a-z manner.

data fin;
input w a x z p;
cards;
1 2 3 5 6
run;

i wna them in a-z manner
a p w x z

how can i do it.
8 REPLIES 8
milts
Pyrite | Level 9
Hi R_Win,

try this one.

proc transpose data=fin out=trans;
var _all_;
run;

proc sort data=trans;
by _name_;
run;

proc transpose data=trans out=trans2;
run;


Regards,
Milton
data_null__
Jade | Level 19
The data set flip-flop using TRANSPOSE is a useful technique. However, it will cause all variables to be converted to character if any variables in the VAR list are character. The conversion to character can be a useful but that is another subject.

You can use DICTIONARY.COLUMNS to produce a alphabetical list of variables. Although there will be problems with that if any of the variables are members of an enumerated variable lists. For example B1-B10 will come out B1 B10 B2 and so on. PROC CONTENTS produces the correct ordering.


[pre]
data fin;
input w a x z p;
B5=1;
array b[10];
cards;
1 2 3 5 6
;;;;
run;
proc sql noprint;
select name into :alphaList separated by ' '
from dictionary.columns
where libname eq 'WORK' and memname eq 'FIN'
order by 1
;
quit;
run;
/* use ALPHALIST as you see fit */
%put NOTE: ALPHALIST=&alphalist;


/* correct order for alphalist with enumerated variables list*/

proc contents noprint order=ignorecase out=alphalist(keep=name);
run;

proc sql noprint;
select name into :alphaList separated by ' '
from alphalist
;
quit;
run;
/* use ALPHALIST as you see fit */
%put NOTE: ALPHALIST=&alphalist;
[/pre]
Doc_Duke
Rhodochrosite | Level 12
Another approach is to populate the "program data vector" with the names in the order that you want before doing the input statement. (search the documentation for 'program data vector' for more than you may want to know; there are some kinks if you mix numeric and character variables).

In your example, adding a KEEP statement before the INPUT will produce the desired results.

data fin;
KEEP a p w x z;
input w a x z p;
cards;
1 2 3 5 6
run;
data_null__
Jade | Level 19
KEEP wont do that. I think I may have in the "old" days V5 and before. No way to test that now.

[pre]
data fin;
KEEP a p w x z;
put (_all_)(=); ** Shows that no variables are defined at this point in program*;
input w a x z p;
cards;
1 2 3 5 6
;
run;
proc contents varnum;
run;
[/pre]
Doc_Duke
Rhodochrosite | Level 12
You are showing my age!

Replacing the KEEP with a LENGTH statement will work.
LENGTH a p w x z 4;
Flip
Fluorite | Level 6
There was a long thread or 2 about this a while back. RETAIN works without having to specify the variable type.
deleted_user
Not applicable
Hi to all,

try to see this

Sample 24696: Reordering variables to be in alphabetical order

http://support.sas.com/kb/24/696.html
sarathannapareddy
Fluorite | Level 6
/*Put all the variables into Alphabetical order;*/

data fin;
input w a x z p;
cards;
1 2 3 5 6
run;

proc sql noprint;
select name into: new separated by ','
from dictionary.columns where libname='WORK' and memname='FIN'
order by name;
create table fin_1 as select &new. from fin;
run;

Read more : http://studysas.blogspot.com/2009/07/dictionary-tables-and-sashelp-views.html

Sarath

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 8 replies
  • 914 views
  • 0 likes
  • 7 in conversation