Discussion:
To create data with variable names in same order
(too old to reply)
Premalatha T
2005-08-08 20:48:08 UTC
Permalink
Hi,

I have to create a SAS data set and I don't want the variable names to be sorted alphabetically. I want the variable names to be in the same order that I give. May I know how to do this??

Thank You for the help.

-Premalatha


---------------------------------
Start your day with Yahoo! - make it your home page
Droogendyk, Harry
2005-08-08 20:51:03 UTC
Permalink
SAS does not create data sets with variables in alphabetical order. However, PROC CONTENTS outputs the variables in alphabetical order by default. If you look at the # column in the output, that indicates the actual variable position within the data set.

-----Original Message-----
From: owner-sas-***@listserv.uga.edu
[mailto:owner-sas-***@listserv.uga.edu]On Behalf Of Premalatha T
Sent: Monday, August 08, 2005 4:48 PM
To: SAS-L
Subject: To create data with variable names in same order


Hi,

I have to create a SAS data set and I don't want the variable names to be sorted alphabetically. I want the variable names to be in the same order that I give. May I know how to do this??

Thank You for the help.

-Premalatha


---------------------------------
Start your day with Yahoo! - make it your home page
__________________________________________________________________________________________________________________________________

This e-mail may be privileged and/or confidential, and the sender does not waive any related rights and obligations.
Any distribution, use or copying of this e-mail or the information it contains by other than an intended recipient is unauthorized.
If you received this e-mail in error, please advise me (by return e-mail or otherwise) immediately.

Ce courrier électronique est confidentiel et protégé. L'expéditeur ne renonce pas aux droits et obligations qui s'y rapportent.
Toute diffusion, utilisation ou copie de ce message ou des renseignements qu'il contient par une personne autre que le (les) destinataire(s) désigné(s) est interdite.
Si vous recevez ce courrier électronique par erreur, veuillez m'en aviser immédiatement, par retour de courrier électronique ou par un autre moyen.
Richard A. DeVenezia
2005-08-08 21:38:29 UTC
Permalink
Post by Premalatha T
Hi,
I have to create a SAS data set and I don't want the variable names
to be sorted alphabetically. I want the variable names to be in the
same order that I give. May I know how to do this??
To list the table metadata in column number order use the Proc CONTENTS
option VARNUM.

To view the data in, say in ViewTable, in some specific order, use a View to
rearrange the columns in the order you want; or create the table with the
specific column ordering in the first place

proc sql;
create view myDataMyWay as select X,Y,A,Z,B from myData;

or

data myData;
* create table with column names ordered the way I want them;
attrib
X length=8 format=9.4 label='This is X'
Y...
A...
Z...
B length = $30 label='To B or not to B, that is the question'
;
infile wherever;
input A B X Y Z;
...
run;
--
Richard A. DeVenezia
http://www.devenezia.com/
Toby
2005-08-08 22:01:18 UTC
Permalink
Premalatha,

I hope you will find one of these helpfull. Just adding to the pool of
helkpful suggestions.

/************************************/

/** Create a Dummy data set **/

/************************************/

data a ;

input x a j z$ q $ ;

cards ;

1 2 3 qwe asd

;

run ;







/******************************************/

/** Method 1: Use when all the vars you **/

/** to reorder comprise less than 32K of **/

/** space. **/

/******************************************/



Proc sql noprint ;

select name into : VarList separated by ' , '

from dictionary.columns

where libname = %upcase("WORK")

and memname = %upcase("A")

order by name ;



create table final as

select &VarList

from a ;



quit ;





/*****************************************/

/** Or if a pure SQL Solution is too **/

/** much SQL for you try a hybrid. **/

/*****************************************/

Proc Sql noprint ;

select name into : VarList separated by ' '

from dictionary.columns

where libname = %upcase("WORK")

and memname = %upcase("A")

order by name ;

quit ;



data final ;

retain &VarList ;

set A ;

run ;







/********************************************/

/** Now if you have a really huge file that**/

/** has a large number of vars you can do **/

/** following. **/

/********************************************/



proc sql ;

create table alpha as

select name

from dictionary.columns

where libname = %upcase("WORK")

and memname = %upcase("A")

order by name ;

quit ;



filename holdvars TEMP;



data _null_ ;

file holdvars ;

set Alpha end = eof ;



IF _n_ = 1 then put 'retain ' name ;



put name ;



If eof then put ';' ;

run ;





data final ;

%include holdvars ;

set a ;

run ;

Toby Dunn
Venky Chakravarthy
2005-08-09 18:27:42 UTC
Permalink
In addition to this if you want to view the columns in a certain order in
the Viewtable, you can do so with commands. For example you have a data set
with variables A to Z and you want to view only Z B and W in that order.
Open the table in the viewer and type

columns 'Z B W'

in the command line or the command box.

Venky

On Mon, 8 Aug 2005 17:38:29 -0400, Richard A. DeVenezia
Post by Richard A. DeVenezia
Post by Premalatha T
Hi,
I have to create a SAS data set and I don't want the variable names
to be sorted alphabetically. I want the variable names to be in the
same order that I give. May I know how to do this??
To list the table metadata in column number order use the Proc CONTENTS
option VARNUM.
To view the data in, say in ViewTable, in some specific order, use a View
to
Post by Richard A. DeVenezia
rearrange the columns in the order you want; or create the table with the
specific column ordering in the first place
proc sql;
create view myDataMyWay as select X,Y,A,Z,B from myData;
or
data myData;
* create table with column names ordered the way I want them;
attrib
X length=8 format=9.4 label='This is X'
Y...
A...
Z...
B length = $30 label='To B or not to B, that is the question'
;
infile wherever;
input A B X Y Z;
...
run;
--
Richard A. DeVenezia
http://www.devenezia.com/
Continue reading on narkive:
Loading...