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

I currently have this SAS program:

%let i = 1;

%macro test;

  %let x = %scan(&idlist,&i,'*');

%do %until (&x= );

%put "&x";

ods html file="/sasdata//temp&x .xls" headtext="<style>

td {mso-number-format:\@}</style>";

proc print data=libanme.tablename uniform label;

     var col1 col2 col3 col4 col5;

      where col1  ="&x";

run;

ods html close;

      %put "&x";

        %let i = &i +1;

         %let x = %scan(&idlist,&i,'*');

%end;

%mend test;

%test;

This program creates a separate xls file in each iteration.

My objective is to create a single dataset and append result of each iteration to that dataset and create a single output xls file containing the entire dataset.

1 ACCEPTED SOLUTION

Accepted Solutions
TomKari
Onyx | Level 15

Here's one way;

First, I'd put "proc sql; drop table want; quit;" right after "%macro test;". It's not required as long as you remember to delete your append dataset after each test, but I ALWAYS forget!

Then, inside the loop, in place of your proc print and ODS statements, try:

proc append base=want data=tablename(where=(col1 ="&x"));

and then your proc print and ODS statements can go after your %end;

Tom

View solution in original post

3 REPLIES 3
TomKari
Onyx | Level 15

I'm not quite clear on what you're trying to do.

It looks to me like each xls file contains the result of your "where" clause. To contain the entire dataset, wouldn't you just remove the "where" clause?

Tom

eagles_dare13
Obsidian | Level 7

Thanks. What I want is that each iteration would contain a result of the where clause and append this result to a master data set. And then output this dataset in form of xls.

So if the table contains 1 million records and each iteration contains 5 records as per the where clause and if there are 5 iterations, then i want a single dataset created with the 5 * 5 = 25 records. And then output this dataset in xls.

TomKari
Onyx | Level 15

Here's one way;

First, I'd put "proc sql; drop table want; quit;" right after "%macro test;". It's not required as long as you remember to delete your append dataset after each test, but I ALWAYS forget!

Then, inside the loop, in place of your proc print and ODS statements, try:

proc append base=want data=tablename(where=(col1 ="&x"));

and then your proc print and ODS statements can go after your %end;

Tom

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 1058 views
  • 0 likes
  • 2 in conversation