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?
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.