BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
eagles_dare13
Obsidian | Level 7

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;

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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.

View solution in original post

5 REPLIES 5
Reeza
Super User

You can't easily.

What are you trying to do, perhaps there's another way?

eagles_dare13
Obsidian | Level 7

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;

ballardw
Super User

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.

Ksharp
Super User

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

Ksharp
Super User

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

sas-innovate-2024.png

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.

 

Register now!

How to choose a machine learning algorithm

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.

Discussion stats
  • 5 replies
  • 14579 views
  • 0 likes
  • 4 in conversation