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;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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