How to arrange a 'variables'

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 86
Accepted Solution

How to arrange a 'variables'

Hi,

If i have a 100 variables in random order...how can i re-arrange in my own order..can any one give sample code or example.

Thanks,

Smiley Happy


Accepted Solutions
Solution
‎08-19-2012 09:24 AM
PROC Star
Posts: 7,363

Re: How to arrange a 'variables'

One way of doing that is to use a retain statement in a datastep.  The statement MUST be placed BEFORE the set statement.  e.g.,

data want;

  retain sex height weight age;

  set sashelp.class;

run;

View solution in original post


All Replies
Solution
‎08-19-2012 09:24 AM
PROC Star
Posts: 7,363

Re: How to arrange a 'variables'

One way of doing that is to use a retain statement in a datastep.  The statement MUST be placed BEFORE the set statement.  e.g.,

data want;

  retain sex height weight age;

  set sashelp.class;

run;

Super Contributor
Posts: 1,636

Re: How to arrange a 'variables'

by modifying the code below may save you some typing if you want to arrange your variables in certain way:

data class;

retain name height ht weight wt sex age;

set sashelp.class;

wt=weight;

ht2=height;

ht=height;

run;

proc sql;

  select name into :names separated by ' '

    from dictionary.columns

   where libname='WORK' and memname='CLASS'

    order by name;

%put &names;

data class;

  retain &names;

  set class;

run;

proc print;run;

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 177 views
  • 3 likes
  • 3 in conversation