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 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.
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 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.
proc means data=my_table NOBS N;
where date_field>="1jan21"d;
run;
I'd probably use PROC MEANS.
proc means data=my_table NOBS N;
where date_field>="1jan21"d;
run;
I'd probably use PROC MEANS.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.