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.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.