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

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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