BookmarkSubscribeRSS Feed
Q1983
Lapis Lazuli | Level 10
I am unable to replicate this in a test dataset however please look at this. have is a proc transpose. Notice the cascading variables that end in PCT. Is there a way to rename the four in _NAME_ to something like Stay_Curr and let all entries appear on the same row in order as seen in the want-proc transpose (or some other routine)?? have - proc transpose Group Category _NAME_ DEC20 JAN21 FEB21 MAR21 APR21 Current Count Count_ 736422 730405 722577 721558 704774 Current Count _04_Stay_Pct 0.94515373 1 1 1 1 Current Count _03_Stay_Pct 1 0.951110685 1 1 1 Current Count _02_Stay_Pct 1 1 0.951131852 1 1 Current Count _01_Stay_Pct 1 1 1 0.95324423 1 Current Count _00_Stay_Pct 1 1 1 1 0.956489598 want-proc transpose Group Category _NAME_ DEC20 JAN21 FEB21 MAR21 APR21 Current Count Count_ 736422 730405 722577 721558 704774 Current Count Stay_Curr_Pct 0.94515373 0.951110685 0.951131852 0.95324423 0.956489598
3 REPLIES 3
Reeza
Super User
Unfortunately your question is garbled enough to not be legible at this point.
Can you please edit it?

Please show what you've tried as well.
ballardw
Super User

Order of variables in a data set is one of the lowest priority things I can think of doing though apparently many people seem to think it is needed. Anything done inside SAS basically does not care.

If a file you are sending to an output file needs a specific order then create that file at that time.

 

Otherwise you can spend a lot of time fooling around with (ever changing) minutia that actually wastes time and makes code hard to follow.

 

So, why is a specific order of variables/ variable names needed?

 

You already likely have too many variables with data in the names, Mon and Year for example. and your "Count_00" "Count_01" are agravating that for most actual processing/analysis.

mkeintz
PROC Star

@ballardw wrote:

Order of variables in a data set is one of the lowest priority things I can think of doing though apparently many people seem to think it is needed. Anything done inside SAS basically does not care.

If a file you are sending to an output file needs a specific order then create that file at that time.

 

Otherwise you can spend a lot of time fooling around with (ever changing) minutia that actually wastes time and makes code hard to follow.

 

So, why is a specific order of variables/ variable names needed?

 

I can think of a few activities I commonly do in which knowing/using variable order is "needed":

  1. When displaying the data
  2. Expecting the identifier variables (id/date/time/...) to consistently be in a particular position
  3. Variable clusters - i.e.   6 groups of 5 attributes arranged contiguously

True, the above are for looking at the data, not programming.  But I often take advantage of variable order in programming as well, mostly through use of the double dash as a means of generating a list of variable names or array declarations, typically to avoid listing lots of variable names.

 

Or it can also be useful when I might not actually know the variable names of interest.  For example: let's say that I want to interleave A and B, but keep only the variables present in dataset A:

 

data want ;
  if 0 then set a;
  retain _sentinel1 .;
  if 0 then set b;
  retain _sentinel2 .;
  set a b;
  by id;
  drop _sentinel1--_sentinel2;
run;

Yes, this can be done directly in SQL, but there are often many reasons to use a data step instead.

 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 770 views
  • 0 likes
  • 4 in conversation