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

I have a code where i am dropping variables which are not needed but it also removes the label of the datasets. Can anyone help me in how to prevent it.

 

code used is 

call execute(
"data &outlib.." || compress(dataset) || "(drop=" || trim(varlist)
|| ");" || "set &outlib.." || compress(dataset)
|| ";" || "run;"
);

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

Hello @vraj1,

 

Use PROC SQL to drop the variables in order to preserve the dataset label, e.g., like this:

call execute(
"proc sql; alter table &outlib.." || compress(dataset) || " drop " 
|| translate(trim(varlist),',',' ')|| "; quit;"
);

(Ideally, you would create VARLIST as a comma-separated list in the first place.)

 

View solution in original post

3 REPLIES 3
FreelanceReinh
Jade | Level 19

Hello @vraj1,

 

Use PROC SQL to drop the variables in order to preserve the dataset label, e.g., like this:

call execute(
"proc sql; alter table &outlib.." || compress(dataset) || " drop " 
|| translate(trim(varlist),',',' ')|| "; quit;"
);

(Ideally, you would create VARLIST as a comma-separated list in the first place.)

 

vraj1
Quartz | Level 8

This is failing if my varlist has only one variable to drop

 

"proc sql; alter table &out.." || compress(dataset) || " drop "
|| translate(trim(compbl(varlist)),',',' ')|| "; quit;"
);

 

I get the below error:

3 + proc sql;
NOTE: Line generated by the CALL EXECUTE routine.
3 + alter table sE drop ,BEY;
-
22
ERROR 22-322: Expecting a name.

FreelanceReinh
Jade | Level 19

Hi @vraj1,

 

The problem is actually not that varlist contains only one variable name, but that it apparently contains a leading blank (which is then "TRANSLATEd" into a leading comma, which in turn is invalid after "DROP"). The solution is very easy: Just replace "trim" by "strip" to remove both trailing and leading blanks from varlist.

 

(The risk of stray blanks being translated into commas was the reason why I recommended a comma-separated list in varlist.)

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 2249 views
  • 0 likes
  • 2 in conversation