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.
@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":
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.
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.