Hi. I am using PROC SORT Nodupkey to remove duplicate data. The thing is, no matter how i put (KEEP=) statement, the output column is only displaying as per my BY statement.
For example:
proc sort data=ppu_sum2
out=ppu_sum(keep=substationname substationcode voltagetype equipmentname feedertype substationtype datetime) nodupkey;
by substationname substationcode substationtype datetime;
run;
How can i make it output according to the out(KEEP=) statement?
do you mean the order of the columns from left to right?
data want;
retain substationname substationcode voltagetype equipmentname feedertype substationtype datetime;
set ppusum;
run;
I would be very surprised if the KEEP statement is not honored. Are you sure your PROC SORT step ran?
If you are really concerned then move the KEEP= dataset option to the input dataset instead of the output dataset. Why bother keeping the other variables around during the sorting?
Note that you are keeping more variables than you are using in the BY statement. So SAS will just keep the values of the extra variables from the one observation in selects for that BY group.
Maxim 2: Read the Log
If that does not provide a clue, post it here.
Are you sure that ppu_sum2 contains all the variables you have in the keep= option?
"Never works" is awful vague.
Are there errors in the log?: Post the code and log in a code box opened with the {i} to maintain formatting of error messages.
No output? Post any log in a code box.
Unexpected output? Provide input data in the form of data step code pasted into a code box, the actual results and the expected results. Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: