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;"
);
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.)
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.)
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.
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.)
Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.
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.