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.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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