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

Hello!

I'm new to SAS Programming. I have the following code:

proc contents data=my_table;
where date_field>="1jan21"d;
run;

The above throws warning. The variable date_field is formatted as numeric. What am I doing wrong?

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

@current_thing wrote:
Hello. I wanted to get a count of observations based on the date filter. That same where clause works fine in the print procedure, so I know the syntax is correct

PROC CONTENTS does NOT count observations. It just reports whatever count the metadata of the dataset already had stored. 

 

To count use some other procedure, like PROC FREQ, PROC MEANS (aka PROC SUMMARY) or PROC SQL.

 

You could also just use a data step.

data _null_;
  set my_table;
  where date_field>="1jan21"d;
run;

And see the number of observations that met the WHERE condition in the NOTEs generated by the data step.

View solution in original post

5 REPLIES 5
Reeza
Super User

That's an interesting filter to have on a PROC CONTENTS....can you explain what you're trying to do?


PROC CONTENTS displays the variable name, label, type which doesn't change regardless of filters. 

 


@current_thing wrote:

Hello!

I'm new to SAS Programming. I have the following code:

proc contents data=my_table;
where date_field>="1jan21"d;
run;

The above throws warning. The variable date_field is formatted as numeric. What am I doing wrong?


 

current_thing
Obsidian | Level 7
Hello. I wanted to get a count of observations based on the date filter. That same where clause works fine in the print procedure, so I know the syntax is correct
Tom
Super User Tom
Super User

@current_thing wrote:
Hello. I wanted to get a count of observations based on the date filter. That same where clause works fine in the print procedure, so I know the syntax is correct

PROC CONTENTS does NOT count observations. It just reports whatever count the metadata of the dataset already had stored. 

 

To count use some other procedure, like PROC FREQ, PROC MEANS (aka PROC SUMMARY) or PROC SQL.

 

You could also just use a data step.

data _null_;
  set my_table;
  where date_field>="1jan21"d;
run;

And see the number of observations that met the WHERE condition in the NOTEs generated by the data step.

Reeza
Super User
proc means data=my_table NOBS N;
where date_field>="1jan21"d;
run;

I'd probably use PROC MEANS.

Reeza
Super User
proc means data=my_table NOBS N;
where date_field>="1jan21"d;
run;

I'd probably use PROC MEANS.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 5 replies
  • 907 views
  • 1 like
  • 3 in conversation