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

Hello,

 

imagine that in my /folder1/subfolder1 , I have dataset named as below

 

test_d20210601

test_d20210602

...

test_d20210630

 

What I would like to do is to take the first dataset (test_d20210601) and rename it global.  Thereafter to append all the other datasets into the global.

 

Here's my code:

 

libname src2 spde '/folder1/subfolder1';
data _null_;
length fname $ 20;
format date yymmddn8.;

do date='01JUN2021'd to '30JUN2021'd;
IF put(date,yymmddn8.) eq 20210601 then
do;
fname=strip(cats('test_d',put(date,yymmddn8.)));
put fname;
/*
Data global;
set src2.fname;
run;
*/

end;
else
do;
fname=strip(cats('test_dd',put(date,yymmddn8.)));
put fname;
/*
fname=strip(cats('test_d',put(date,yymmddn8.)));
proc append base=global data=src2.fname;
run;
*/


end;
END;

run;

 

This code works perferctly if I want to get the fname into the log file.

However, if I want to comment the put fname and comment out the piece of code that was comment in, it is not working.

 

What's wrong in my code.

Is it possible to create a dataset then append the other the way I would like to do it?

if not what's the best way?

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
2 REPLIES 2
Reeza
Super User
Your code is nesting data step statements inside loops incorrectly. If you want to conditionally execute code you need to use macro code or to use CALL EXECUTE or DOSUBL so how you're building your program is incorrect. You have the correct concepts but not the correct syntax. FYI - this is very similar to issues in your previous questions and the answer/solution is the same idea.

Also, is there a point to automating this? This seems like something you'd do once so what's the point of generating nice code to automate this? Wouldn't the code below generate the exact same results?

data global;
set d202106: ;
run;

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!

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