In SAS, how can I do the equivalent of:
data a;
set b;
if (somecondition = true)
drop col2; /*col2 is a column included in b*/
run;
Your example doesn't do what you think when I supply data and a variety of conditions. But there are no syntax errors so it creates dataset A identical to B. Run proc compare on the two.
HINT: see what happens with If condition then drop col2; <= This is a syntax error with a "Statement is not valid or it is used out of proper order.
Drop is more of a global statement and isn't conditional.
This isn't how it works but consider this scenario:
Suppose the first record doesn't meet your condition. Then col2 is written to the output dataset. The column will now be present for all records regardless.
You can exclude entire records from your output.
You can change the value of the variable for specific records.
The variable (column) is either present or not.
You can't easily.
What are you trying to do, perhaps there's another way?
Thanks.
This seems to work, but is it correct?
In SAS, how can I do the equivalent of:
data a;
set b;
if (somecondition = true) then do;
drop col2;
end;/*col2 is a column included in b*/
run;
Your example doesn't do what you think when I supply data and a variety of conditions. But there are no syntax errors so it creates dataset A identical to B. Run proc compare on the two.
HINT: see what happens with If condition then drop col2; <= This is a syntax error with a "Statement is not valid or it is used out of proper order.
Drop is more of a global statement and isn't conditional.
This isn't how it works but consider this scenario:
Suppose the first record doesn't meet your condition. Then col2 is written to the output dataset. The column will now be present for all records regardless.
You can exclude entire records from your output.
You can change the value of the variable for specific records.
The variable (column) is either present or not.
If I understood what you mean , you need two data step to get it. One is to pick up column name, the other is to drop column.
data _null_;
set class;
if name='Arthur' then call symputx('drop','age');
run;
data want;
set class;
drop &drop ;
run;
Xia Keshan
If I understood what you mean , you need two data step to get it. One is to pick up column name, the other is to drop column.
data _null_;
set class;
if name='Arthur' then call symputx('drop','age');
run;
data want;
set class;
drop &drop ;
run;
Xia Keshan
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 25. Read more here about why you should contribute and what is in it for you!
Use this tutorial as a handy guide to weigh the pros and cons of these commonly used machine learning algorithms.
Find more tutorials on the SAS Users YouTube channel.