BookmarkSubscribeRSS Feed
Ronein
Meteorite | Level 14

Hello,

I want to create a new data set using set statement.

IF the data set dosn't exit then I want that nothing will be done(data set will not created) and there will not be an error.

 

The error is 

NOTE: Line generated by the invoked macro "IF_EXIST_OLD".
31          r_r.Panel
            ____________________________
            557
ERROR: DATA STEP Component Object failure.  Aborted during the COMPILATION phase.
ERROR 557-185: Variable r_r is not an object.

 


%macro if_exist_old;
%if %sysfunc(exist(r_r.Panel)) %then r_r.Panel;
%mend;
Data r_r.Backup;
%if_exist_old;
Run;
16 REPLIES 16
PaigeMiller
Diamond | Level 26

You don't have a SET statement in your code.

 

This is why we advise people to create working SAS code without macros before you try to write a macro. In this case, you need working SAS code for the case where the data set exists, and also working code for the case where the data set doesn't exist. If you had this, you would have a much better chance of achieving your goal of creating code for these situations.

--
Paige Miller
PaigeMiller
Diamond | Level 26

@Kurt_Bremser wrote:

You can do it without a macro nowadays:

data r_r.backup;
set
%if %sysfunc(exist(r_r.panel))
%then %do;
  r_r.panel
%end;
;
run;

I don't believe that the OP has SAS 9.4 TS1M5 which I think is required for this to work.

--
Paige Miller
Reeza
Super User
That will technically create an empty data set.
Patrick
Opal | Level 21

@Kurt_Bremser wrote:

You can do it without a macro nowadays:

data r_r.backup;
set
%if %sysfunc(exist(r_r.panel))
%then %do;
  r_r.panel
%end;
;
run;

@Kurt_Bremser You definitely haven't tested this code. In my environment an "empty" set statement uses _last_ - and using EG there is always a _last_. And with SET also in the macro condition an empty data set gets created.

andreas_lds
Jade | Level 19

I am sure you can adept the solution provided provided in your older thread: https://communities.sas.com/t5/SAS-Programming/SET-data-sets-IF-exits/m-p/754937#M238173

Ronein
Meteorite | Level 14

Hello,

The target is :

IF data set ABC exist then create a new data set called wanted (using SET statement).

IF data set ABC doesnt exist then do nothing! (No create empty data set).

I  run this code and get a strange results.

Data set ABC doesn't exist but I get a data set wanted with following columns

Ronein_0-1634536540695.png

 

 

 

%macro if_exist_old;
%if %sysfunc(exist(ABC)) %then ABC;
%mend;
Data wanted;
SET
%if_exist_old;
Run;
Ronein
Meteorite | Level 14
Sorry I didn't understand the problem, may you please show the code
Ronein
Meteorite | Level 14
Yes but my question was why way2 is not working well and what is this data set that was created?

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 16 replies
  • 1546 views
  • 4 likes
  • 7 in conversation