I'm trying to do the following with PROC SORT:
DATA FOO; INPUT name $; DATALINES; nassau suffolk westchester putnam ; RUN; PROC SQL; SELECT * FROM FOO ORDER BY CASE name WHEN 'westchester' THEN 1 WHEN 'putnam' THEN 2 WHEN 'suffolk' THEN 3 WHEN 'nassau' THEN 4 END; QUIT;
You'd still need to create those new variables in a prior step and then sort accordingly.
AFAIK there's no way to incorporate that into the PROC SORT directly, which is what I assume you're asking.
@tomcmacdonald wrote:
I'm trying to do the following with PROC SORT:
DATA FOO; INPUT name $; DATALINES; nassau suffolk westchester putnam ; RUN; PROC SQL; SELECT * FROM FOO ORDER BY CASE name WHEN 'westchester' THEN 1 WHEN 'putnam' THEN 2 WHEN 'suffolk' THEN 3 WHEN 'nassau' THEN 4 END; QUIT;
You'd still need to create those new variables in a prior step and then sort accordingly.
AFAIK there's no way to incorporate that into the PROC SORT directly, which is what I assume you're asking.
@tomcmacdonald wrote:
I'm trying to do the following with PROC SORT:
DATA FOO; INPUT name $; DATALINES; nassau suffolk westchester putnam ; RUN; PROC SQL; SELECT * FROM FOO ORDER BY CASE name WHEN 'westchester' THEN 1 WHEN 'putnam' THEN 2 WHEN 'suffolk' THEN 3 WHEN 'nassau' THEN 4 END; QUIT;
And the question is?
"I'm trying to do the following the PROC SORT" doesn't make much sense.
You need to check your example data. The way you read your data you do not have a value of "Westchester" only "westches" . $ without an informat or similar to tell SAS the variable is longer than 8 characters results in truncated data.
DATA foo; INPUT name $12.; DATALINES; nassau suffolk westchester putnam ; RUN;
If you were not getting expected results you should show the results you were getting and what you expected
Are you attempting to use the proc sql instead of proc sort?
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.