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

I know this has been asked a couple times before, but whatever method I try, I can't get this to work.

 

I have a dataset named log2_trimm, containing trimmed error messages that were found in log .txt files. If no errors are found in that file, the dataset is created and sits empty. If it does contain observations, it is printed as a list I can read through. I use this for knowing when crosstabulations aren't performed due to empty cells.

 

I've tried variations of this approach, which I found on another SAS Communities question solution:

	data  use_this_if_no_obs;
	  msg='No Empty Cells';
	run;

	data _null_;
		set sashelp.vtable (where=(libname="WORK" and memname="log2_trimm"));
	  		if nobs=0 then call execute('proc print data=use_this_if_no_obs; run;');
	  		Else if nobs GE 1 then call execute('proc print data=log2_trimm; run;');
	run;

I only get the error message:

4020 data use_this_if_no_obs;
4021 msg='No Data';
4022 run;

NOTE: The data set WORK.USE_THIS_IF_NO_OBS has 1 observations and 1 variables.
NOTE: DATA statement used (Total process time):
real time 0.03 seconds
cpu time 0.03 seconds


4023
4024 data _null_;
4025 set sashelp.vtable (where=(libname="WORK" and memname="log2_trimm"));
4026 if nobs=0 then call execute('proc print data=use_this_if_no_obs; run;');
4027 Else if nobs GE 1 then call execute('proc print data=log2_trimm; run;');
4028 run;

 

NOTE: Data file SASUSER.SASMBC.DATA is in a format that is native to another host, or the file
encoding does not match the session encoding. Cross Environment Data Access will be used,
which might require additional CPU resources and might reduce performance.
NOTE: There were 0 observations read from the data set SASHELP.VTABLE.
WHERE (libname='WORK') and (memname='log2_trimm');
NOTE: DATA statement used (Total process time):

I know the log2_trimm dataset exists; SAS and I both know it's empty. I also see it in the VTABLE with zero observations. 

 

What gives? What am I doing wrong? I've even tried variations of this, even tried Proc SQL, and it just refuses to print the message.

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

Hello @SAS93,

 

I don't see an error message, but a logical error: The dataset names in SASHELP.VTABLE are written in upper case, so your WHERE condition should read

libname="WORK" and memname="LOG2_TRIMM"

View solution in original post

3 REPLIES 3
FreelanceReinh
Jade | Level 19

Hello @SAS93,

 

I don't see an error message, but a logical error: The dataset names in SASHELP.VTABLE are written in upper case, so your WHERE condition should read

libname="WORK" and memname="LOG2_TRIMM"
SAS93
Quartz | Level 8

THANK YOU, that solved the problem! I did not realize working with the dictionary tables was case-sensitive. 

Tom
Super User Tom
Super User

The values of LIBNAME and MEMNAME in the various dictionary tables are always in uppercase. Searching for a member name with lowercase letters will never match.

 

But if you know the input dataset exists then you can use a simple data step to check if it has observations or not. No need to search the dictionary metadata tables.

data _null_;
  if nobs then call execute('proc print data=log2_trimm; run;');
  else call execute('proc print data=use_this_if_no_obs; run;');
  stop;
  set log2_trimm nobs=nobs;
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!

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
  • 3 replies
  • 1164 views
  • 1 like
  • 3 in conversation