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

Hi! 

 

the if exists function doesn't work for view only for table how can i make it work?

code snippet:

%do i=&yymm.01 %to &yymm.31;
   %if %sysfunc(exist(test.a&i.,'VIEW')) %then %do;
     data _null_;
      call symput('_tmp_act_dt_',strip(input("&i.",yymmdd6.)));
     run;

I always get FALSE but the view is an existing view.

 

%DO loop beginning; index variable I; start value is 200201;

stop value is 200231; by value is 1.

SYMBOLGEN:  Macro variable I resolves to 200201

MLOGIC(test_macro):  %IF condition %sysfunc(exist(da_d2.ut&i.,'VIEW')) is FALSE

MLOGIC(test_macro):  %DO loop index variable I is now 200202; loop will iterate

 

thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

The EXIST() function only supports one of these two four character strings: DATA  or VIEW.  It does not support the six character string you tried to use.  To the macro processor everything is a string so there is no need to add quotes to distinguish between a string and a name.

%if %sysfunc(exist(test.a&i.,VIEW)) %then %do;

 

View solution in original post

5 REPLIES 5
PaigeMiller
Diamond | Level 26

Show us a screen capture that proves that view da_d2.ut200201 actually exists.

--
Paige Miller
ger15xxhcker
Quartz | Level 8

proof:

(how can i set a table if not exist). if exist can not work with view table? What can i do?

 

%macro xxx;

   %if %sysfunc(exist(da_d2.ut200208)) %then 1=1;

%mend;

 

%xxx;

 

data test;

set da_d2.ut200208;

run;

 

%macro xxx;

   %if %sysfunc(exist(test)) %then 1=1;

%mend;

 

%xxx;

 

LOG:

 

NOTE: Remote submit to SRV1 commencing.

71193   %macro xxx;

71194      %if %sysfunc(exist(da_d2.ut200208)) %then 1=1;

71195   %mend;

71196

71197   %xxx;

MLOGIC(XXX):  Beginning execution.

MLOGIC(XXX):  %IF condition %sysfunc(exist(da_d2.ut200208)) is FALSE

MLOGIC(XXX):  Ending execution.

71198

71199   data test;

71200   set da_d2.ut200208;

71201   run;

 

NOTE: View DA_D2.UT200208.VIEW used (Total process time):

      real time           29.30 seconds

      cpu time            13.18 seconds

 

NOTE: There were 554536 observations read from the data set DA_D2.UT200208.

NOTE: The data set WORK.TEST has 554536 observations and 162 variables.

NOTE: Compressing data set WORK.TEST decreased size by 59.06 percent.

      Compressed is 5160 pages; un-compressed would require 12604 pages.

NOTE: DATA statement used (Total process time):

      real time           29.50 seconds

      cpu time            13.33 seconds

 

 

71202

71203   %macro xxx;

71204      %if %sysfunc(exist(test)) %then 1=1;

71205   %mend;

71206

71207   %xxx;

MLOGIC(XXX):  Beginning execution.

MLOGIC(XXX):  %IF condition %sysfunc(exist(test)) is TRUE

PaigeMiller
Diamond | Level 26

Your new code does not search to see if a VIEW exists, it searches to see if a data set exists, and apparently no such data set exists. You left out that parameter from the EXIST function.

 

 

--
Paige Miller
Tom
Super User Tom
Super User

The EXIST() function only supports one of these two four character strings: DATA  or VIEW.  It does not support the six character string you tried to use.  To the macro processor everything is a string so there is no need to add quotes to distinguish between a string and a name.

%if %sysfunc(exist(test.a&i.,VIEW)) %then %do;

 

ballardw
Super User

Don't put the quotes around the member type when using %sysfunc.

 

data work.junk /view=work.junk;
   set sashelp.class;
run;

%let result =  %sysfunc(exist(work.junk,VIEW));
%put &result;

Gets me a result of:

39   %put &result;
1

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
  • 5 replies
  • 2077 views
  • 2 likes
  • 4 in conversation