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


Hi,

I want to change a variable in a data.

But I want to do the same job for multiple files in a directory.

I kind of feel that I can do this efficiently if I use macro, but I do not know exactly becuase I am  just a beginner of SAS macro.

The SAS code for one file is..

data test;

set pars.prod11_beer;

COLUPC = 1*UPC

drop UPC;

run;

Any advice or suggetion from you would be greatly appreciated!

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
Jagadishkatam
Amethyst | Level 16

Hi ,

Please try the below macro

%macro dir(name=,file=,var=,var2=);

data &name;

set pars..&file;

&var= 1*&var2

drop &var2;

run;

%mend;

%dir(name=test, file=prod11_beer,var=COLUPC,var2=UPC);

Hope this helps

Thanks,

Jagadish

Thanks,
Jag

View solution in original post

4 REPLIES 4
Jagadishkatam
Amethyst | Level 16

Hi ,

Please try the below macro

%macro dir(name=,file=,var=,var2=);

data &name;

set pars..&file;

&var= 1*&var2

drop &var2;

run;

%mend;

%dir(name=test, file=prod11_beer,var=COLUPC,var2=UPC);

Hope this helps

Thanks,

Jagadish

Thanks,
Jag
jhhuh
Calcite | Level 5

Thanks.

But it did not work well..

I got the error message below.

error.jpg

Do you have any idea why this happened?

Jagadishkatam
Amethyst | Level 16

Hi

Please remove the additional . from pars..&file, there should be a single . like this

pars.&file

Please try and let me know the output.

Thanks,

Jagadish

Thanks,
Jag
jhhuh
Calcite | Level 5

Thank you so much!

It worked beautifully!

Jin-Hee Huh

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 4 replies
  • 888 views
  • 3 likes
  • 2 in conversation