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

good day,

 

here is the code i wrote. the program logic is to extract the data i needed and put it in ned data set with a new assigned name.

 

any skill can enhance this script? can i just simply mark the new_name in old data set?

 

instead of draw them out and append to a new data base.

 

i just find out i create many data sets and waste tons of time on waiting.

 


%macro sqlmerchant(A=,B=,C=,D=);
PROC SQL;
CREATE TABLE &A AS
SELECT * ,"&b" AS NAME ,"Y" as Cleaned_flag FROM TESTING
WHERE NEW2 LIKE &C
AND "Merchant Category"N IN &D
;


DELETE FROM TESTING
WHERE NEW2 LIKE &C
AND "Merchant Category"N IN &D
;

create table DATA_&A as
select * from &A
;
quit;

proc append base=testing2
data=DATA_&A ;
run;

%MEND;

%sqlmerchant(A=AIRSTANA,b=AIR STANA,C="%AIRASTANA%",D=("Airlines----AIR STANA"));
%sqlmerchant(A=AIRSTANA,b=AIR STANA,C="%AIRSTANA%",D=("Airlines----AIR STANA"));

 

thanks for the helping,

Harry

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisNZ
Tourmaline | Level 20

This should work much faster.

%macro sqlmerchant(name=,test=);
  if &test then do;
    Cleaned_flag="Y";
    NAME="name";
  end;
%mend;

data TESTING;
  modify TESTING;
  %sqlmerchant(name=AIRSTANA, test=index(NEW2,"AIRSTANA")  & "MerchantCategory"n in ("Airlines----AIR STANA") );
  %sqlmerchant(name=AIRSTANA, test=index(NEW2,"AIRASTANA") & "MerchantCategory"n in ("Airlines----AIR STANA") );
run;

Note that MODIFY does not allow creating columns.

If that's an issue, use SET instead.

 

 

View solution in original post

3 REPLIES 3
ChrisNZ
Tourmaline | Level 20

This should work much faster.

%macro sqlmerchant(name=,test=);
  if &test then do;
    Cleaned_flag="Y";
    NAME="name";
  end;
%mend;

data TESTING;
  modify TESTING;
  %sqlmerchant(name=AIRSTANA, test=index(NEW2,"AIRSTANA")  & "MerchantCategory"n in ("Airlines----AIR STANA") );
  %sqlmerchant(name=AIRSTANA, test=index(NEW2,"AIRASTANA") & "MerchantCategory"n in ("Airlines----AIR STANA") );
run;

Note that MODIFY does not allow creating columns.

If that's an issue, use SET instead.

 

 

harrylui
Obsidian | Level 7
thanks fro your help
enatx
Calcite | Level 5

@harrylui wrote:

good day,

 

here is the code i wrote. the program logic is to extract the data i needed and put it in ned data set with a new assigned name.

 

any skill can enhance this script? can i just simply mark the new_name in old data set?

 

instead of draw them out and append to a new data base about.

 

i just find out i create many data sets and waste tons of time on waiting.

 


%macro sqlmerchant(A=,B=,C=,D=);
PROC SQL;
CREATE TABLE &A AS
SELECT * ,"&b" AS NAME ,"Y" as Cleaned_flag FROM TESTING
WHERE NEW2 LIKE &C
AND "Merchant Category"N IN &D
;


DELETE FROM TESTING
WHERE NEW2 LIKE &C
AND "Merchant Category"N IN &D
;

create table DATA_&A as
select * from &A
;
quit;

proc append base=testing2
data=DATA_&A ;
run;

%MEND;

%sqlmerchant(A=AIRSTANA,b=AIR STANA,C="%AIRASTANA%",D=("Airlines----AIR STANA"));
%sqlmerchant(A=AIRSTANA,b=AIR STANA,C="%AIRSTANA%",D=("Airlines----AIR STANA"));

 

thanks for the helping,

Harry


Did you resolve this issue ?

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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
  • 1166 views
  • 0 likes
  • 3 in conversation