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-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!

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.

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