BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
crankydogg
Calcite | Level 5

I am trying to figure out how many surveys have been completed each month so far this year.  I used the following:

 

count=intck('survey_complete','01apr2021'd, '01may2021'd)

 

And received the following error:

 

ERROR 180-322: Statement is not valid or it is used out of proper order.

 

I am also unsure if this is a stand alone statement, a data step, or something else entirely.

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
The YYMMN6 format WILL NOT work on a datetime variable.

The DTMONYY5 format WILL work on a datetime variable.

Did you use a datetime variable or date variable? Is your variable a SAS date/datetime, ie numeric with a format attached? If its a character value that may explain what you're seeing to some degree but then you should have a note or error in the log.

Here's an example of how this works, converting months to years in this case:
https://gist.github.com/statgeek/0cae5568752959b035516d6ac07a20fb

View solution in original post

11 REPLIES 11
PaigeMiller
Diamond | Level 26

Your statement using INTCK can only be valid inside a data step, and must end with a semi-colon. The first argument must be a calendar interval like 'month' or 'year', it can't be 'survey_complete' which is not recognized.

 

Please show some sample data and explain what you are trying to do in more detail.

--
Paige Miller
Reeza
Super User
If I understand your problem correctly, you should be using PROC FREQ most likely. Assuming you have a variable named 'survey_complete', which is a variable that has the date the survey was completed in a data set called 'have' your code would look like the following. Note the usage of a format on the date so that the data is aggregated at the monthly level rather than the daily level.


proc freq data=have;
table survey_complete /missing out=summary_month;
format survey_complete yymmn6.;
run;
crankydogg
Calcite | Level 5

Thank you for the information.  I just realized that the survey_complete variable also has a time stamp so the information is shown as:

9/14/2021 2:21:00 PM

 

My ultimate goal is to be able to have the data to create a table like the following:

MonthSurveys Completed
January3
February5
March10

 

 

 

 

 

 

Reeza
Super User
That means you have a datetime variable, not a date variable.

Change the format in my code to :

DTMONYY5 then to show the dates as Mar2018.
https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/leforinforref/p0b84w2ylz4givn13sgq4umehexc.ht...

If you would like a different format, in a prior step convert the datetime variable to a date variable using the DATEPART() function THEN reapply my original solution.
crankydogg
Calcite | Level 5

This really helped, thanks!  The table prints just fine, but the months are not merging.  Please see example below.  Any suggestions?

 

proc freq data=grace;
table survey_timestamp /missing out=summary_month;
format survey_timestamp;
run;

 

survey_timestampFrequencyPercentCumulativeCumulative
FrequencyPercent
 2252.382252.38
5/24/202112.382354.76
6/10/202112.382457.14
6/21/202112.382559.52
7/14/202112.382661.9
7/15/202112.382764.29
7/9/202112.382866.67
8/13/202112.382969.05
8/18/202112.383071.43
8/20/202124.763276.19
8/23/202112.383378.57
8/31/202112.383480.95
9/1/202112.383583.33
9/13/202112.383685.71
9/14/202112.383788.1
9/15/202112.383890.48
9/2/202112.383992.86
9/8/202112.384095.24
[not completed]24.7642100
Reeza
Super User
Look at my code and yours, specifically, where did you put the format.
crankydogg
Calcite | Level 5

Hello.  Below is my code for the table (I did add in your DTMONYY5 statement).

 

proc freq data=grace;
table survey_timestamp /missing out=summary_month;
format survey_timestamp DTMONYY5;
run;

 

I formatted it after the code you initially sent:

proc freq data=have;
table survey_complete /missing out=summary_month;
format survey_complete yymmn6.;
run;

 

I am still getting the dates separately, not combined/counted.

PaigeMiller
Diamond | Level 26

At this point, you need to show us some sample data. Plaese follow these instructions. Do not attach files or provide screen captures.

--
Paige Miller
Reeza
Super User
The YYMMN6 format WILL NOT work on a datetime variable.

The DTMONYY5 format WILL work on a datetime variable.

Did you use a datetime variable or date variable? Is your variable a SAS date/datetime, ie numeric with a format attached? If its a character value that may explain what you're seeing to some degree but then you should have a note or error in the log.

Here's an example of how this works, converting months to years in this case:
https://gist.github.com/statgeek/0cae5568752959b035516d6ac07a20fb
crankydogg
Calcite | Level 5

Thank you again for responding.  I did use the DTMONYY5 format and it ran without an error.  I appreciate your help.

 

On a separate note regarding the date/time, I later converted this variable to a character variable in the format of "Month ID" and was able to summarize the data based on this month-id level.

Reeza
Super User
If your month are now character values, then the months won't sort in order if they have values like Jan2021, Feb2021 they sort alphabetically instead.

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