BookmarkSubscribeRSS Feed
daniele_1306
Calcite | Level 5

I have a table like this:

NameEyes_Colour
DanieleBrown
LucaBlue
FrancescaBrown
AntonioBlue
StefanoBrown
VivianaGreen

i want to split this table in 3 table based on Eyes_Colour

Table Brown Table Blue Table Green
NameEyes_Colour NameEyes_Colour NameEyes_Colour
DanieleBrown LucaBlue VivianaGreen
FrancescaBrown AntonioBlue   
StefanoBrown      

 

and i want to export this tables in 3 files xls.

can you help me? 

5 REPLIES 5
Ksharp
Super User

If you don't have a big table .

 

data have;
 set sashelp.heart;
run;


proc freq data=have noprint;
table sex/out=temp;
run;
data _null_;
 set temp;
 call execute(cat('data ',sex,';set have;if sex="',sex,'";run;'));
run;
PeterClemmensen
Tourmaline | Level 20

If you only want the Excel workbooks and do not need the individual SAS data sets, you could do something like this

 

data have;
input Name $9. Eyes_Colour $;
datalines;
Daniele   Brown
Luca      Blue 
Francesca Brown
Antonio   Blue 
Stefano   Brown
Viviana   Green
;

proc sql noprint;
   select distinct Eyes_Colour into :e1 -
   from have;
quit;

%macro odse;

   proc sql noprint;
      select distinct Eyes_Colour into :e1 -
      from have;
   quit;

   %do i = 1 %to &sqlobs.;
      ods excel file = "YourPathHere\&&e&i...xlsx" ;
      
      proc print data = have(where=(Eyes_Colour = "&&e&i"));
      run;

      ods excel close;
   %end;
%mend;

%odse;
daniele_1306
Calcite | Level 5

Excellent, thank you very much! however, in doing so it is first necessary to download the xls (and therefore to open them) and then to save them. it is not possible to save them automatically in the path I indicated

daniele_1306
Calcite | Level 5

can you help me again? I want to automatically export the files without having to download them first.

thank you very much...

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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
  • 5 replies
  • 1203 views
  • 1 like
  • 3 in conversation