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.)

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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