In the following code, I want to remove the duplicates. If I want to add proc sort or proc sql to remove duplicates then how to tweak this code?
%let target_table=&datasource; %global prompt; proc print data="&envPath/data/gb/&datasource" noobs; where ¶meter_1 in ("¶meter_2"); var &_field; run;
You can add proc sort just before proc print. And you might need to specify exact variables in BY statement, if not interested in sorting all variables that listed in &_field macro variable.
%let target_table=&datasource;
%global prompt;
proc sort data= "&envPath/data/gb/&datasource" out=sorted nodupkey /*or noduprecs if sorting all vars*/;
by &_field /* or list of vars */;
run;
proc print data= sorted noobs;
where ¶meter_1 in ("¶meter_2");
var &_field;
run;
@Babloo wrote:
In the following code, I want to remove the duplicates. If I want to add proc sort or proc sql to remove duplicates then how to tweak this code?
Duplicates of what? ¶meter_1? ¶meter_2? &_field?
Really need to learn to use libname.dataset notation. relying on external file syntax is going to cause problems at sometime.
For one thing you only have to debug ONE libname statement and have one assignment for the library. What you have could require changing lots of code when something moves or processing similar data in another location, such as to a different sub-folder like
"&envPath/data/gb_2
Also, do you want to use that data set for anything else? Ever? Especially needing it with the duplicates for that other use? Then your sort would require a different output data set(or view) for the Print step as otherwise the duplicates are permanently gone.
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.