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

I have this dataset frequencies

 

bucketfreqdate
10.49%202004
10.43%202005
10.48%202102
10.46%202103
21.99%202004
22.31%202005
21.89%202006
22.70%202007
22.17%202008
21.72%202009
22.33%202010
22.27%202011
22.60%202012
23.00%202101
22.37%202102
23.06%202103

 

genearted by

 

data frequencies;
    input bucket $1. freq NLPCT7.2 date $6.;
    format freq NLPCT7.2;
    datalines;
1	0.49%	202004
1	0.43%	202005
1	0.48%	202102
1	0.46%	202103
2	1.99%	202004
2	2.31%	202005
2	1.89%	202006
2	2.70%	202007
2	2.17%	202008
2	1.72%	202009
2	2.33%	202010
2	2.27%	202011
2	2.60%	202012
2	3.00%	202101
2	2.37%	202102
2	3.06%	202103
;
run;

The time window should go from 202004 (April 2020) to 202103 (March 2021) but there are some missing frequencies for bucket 1. 

 

When I run the sas program 

proc sgplot data = frequencies;
	title "frequency by date";
  	series x=date y=freq / GROUP=bucket;
	xaxis fitpolicy=rotatethin;
run;

I get the following plot 

Babado_0-1632313502524.png

which, although I know the problem comes from the fact of missing data, I don't understand.

Is there a way to overcome this? 
I would like to have both series plotted for their respective time window if possible. If not possible, I would like the missing frequency values to be assumed 0%.

 

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

Store your date as numeric/date type variable ,NOT character.

 

data frequencies;
    input bucket : $ freq : NLPCT7.2 date : yymmn6. ;
    format freq NLPCT7.2 date yymmn6.;
    datalines;
1	0.49%	202004
1	0.43%	202005
1	0.48%	202102
1	0.46%	202103
2	1.99%	202004
2	2.31%	202005
2	1.89%	202006
2	2.70%	202007
2	2.17%	202008
2	1.72%	202009
2	2.33%	202010
2	2.27%	202011
2	2.60%	202012
2	3.00%	202101
2	2.37%	202102
2	3.06%	202103
;
run;

proc sgplot data = frequencies;
	title "frequency by date";
  	series x=date y=freq / GROUP=bucket;
	xaxis fitpolicy=rotatethin;
run;

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26

I'm not getting the plot you are getting, so do us all a favor (this time, and at all times in the future). Please provide the data as SAS data step code, following these instructions: https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/ Do not provide data as Excel files or screen captures, provide data only as SAS data step code.

--
Paige Miller
Babado
Fluorite | Level 6

Thank you for the advice, as this is my first time using this platform. I edited the post.

Ksharp
Super User

Store your date as numeric/date type variable ,NOT character.

 

data frequencies;
    input bucket : $ freq : NLPCT7.2 date : yymmn6. ;
    format freq NLPCT7.2 date yymmn6.;
    datalines;
1	0.49%	202004
1	0.43%	202005
1	0.48%	202102
1	0.46%	202103
2	1.99%	202004
2	2.31%	202005
2	1.89%	202006
2	2.70%	202007
2	2.17%	202008
2	1.72%	202009
2	2.33%	202010
2	2.27%	202011
2	2.60%	202012
2	3.00%	202101
2	2.37%	202102
2	3.06%	202103
;
run;

proc sgplot data = frequencies;
	title "frequency by date";
  	series x=date y=freq / GROUP=bucket;
	xaxis fitpolicy=rotatethin;
run;

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

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 1036 views
  • 3 likes
  • 3 in conversation