BookmarkSubscribeRSS Feed
Geo-
Quartz | Level 8

Hi, I have a table like:

 

abc
a101b1c1
a102b2c2
a103b3c3

 

and will create 3 excel files like:

table1_b2 
abc
a102b2c2
   
table_b1  
abc
a101b1c1
   
table_b3  
abc
a103b3c3
   

 

 

how to use macro to create and export tables according to  distinct value of column b and create table_&bi,thanks!

5 REPLIES 5
ChrisNZ
Tourmaline | Level 20

You don't need macros.

Something like this works:

 

data _null_;
  set TABLE(keep=B);
  by B;
  if first.B then call execute ('ods excel .....sheet_name= ....    '
                             || 'proc print data=TABLE noobs; where B='||quote(B)||';run;'
                             || 'ods ..... ');
run;

 

 

Geo-
Quartz | Level 8
macro is needed..if column B have hundreds of values,this way could not work
ChrisNZ
Tourmaline | Level 20
And you know this because? Hundreds should work.
Geo-
Quartz | Level 8
data _null_;
  set TABLE(keep=company);
  by company;
  if first.company then call execute ('ods excel file="c:\temp.xlsx"  sheet_name="sales report"    '
                             || 'proc print data=TABLE noobs; where company='||quote(company)||';run;'
                             || 'ods excel close ');
run;

Hi expert ,would you please  check where is wrong with the code

ChrisNZ
Tourmaline | Level 20

1. Missing semicolons

2. You overwrite the same file over and over

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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