Dear All
This is the code that I have written. Am I making a mistake?
Data A B ; Set have;
If VarA = 1 then output A (Drop = VarF (Rename = (VarM = VarMA VarN= VarNA)));
If VarA = 2 then output B (Drop = VarF (Rename = (VarK = VarKA VarL= VarLA)));
run;
I am trying to split the data set "have" into different data sets and rename variables. I can use multiple data steps; but for efficiency I just wanted to use one data statement.
When I run the code; I get an error statement on the "DROP" part of the code
@RandyStan wrote:
When I run the code; I get an error statement on the "DROP" part of the code
Why withhold this information from us in your original post? Anyway, @Tom has explained what the error is.
But rarely do you need to split a data set like this. You could use a BY statement in whatever analyses you are doing, and then the splitting of the data set can be altogether avoided.
Even if you want to do separate analyses when VarA=1 or VarA=2, one data set suffices, and so you may be performing extra unnecessary work, and if this is a large dataset, splitting it like this takes up more storage and more execution time (well, that's also true if it is a small data set, but then you won't really notice the extra execution time). Example:
proc means data=have(where=(vara=1) Drop = VarF Rename = (VarM = VarMA VarN= VarNA));
/* more PROC MEANS statements */
run;
@RandyStan wrote:
This is the code that I have written. Am I making a mistake?
Did you run the code? Did it work? Did you do what you want? How can we know if you are making a mistake?
Also, I have never seen this exact syntax (it may work, but I think it's wrong unless you remove the parentheses that I have colored red
(Drop = VarF (Rename = (VarM = VarMA VarN= VarNA)))
No. You cannot have dataset options on an OUTPUT statement. Those belong where the output dataset is defined.
data
A (Drop = VarF Rename = (VarM = VarMA VarN= VarNA))
B (Drop = VarF Rename = (VarK = VarKA VarL= VarLA))
;
set have;
if VarA = 1 then output A;
if VarA = 2 then output B;
run;
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.