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 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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