BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi Friends

How do i extract month wise data from a table. Here's my code:

proc sql;

%Let Load_date = '01NOV2009'd;

Select DATEPART(PARAM_DATE_LOW)
into :Load_date
From param_table
Where PARAM_ID = 'TABLE1';

/*Store Source Record count to load*/

Select count(*) into :src_rec_count
From source_table src
Where data_column = &Load_date

quit;

let's say PARAM_DATE_LOW has vlaue 01-Nov-09. In this 2nd select statement, I want only november month's data from source_table.

How can I achieve that?

Thanks
2 REPLIES 2
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
You can use the INTNX function in your SELECT statement along with your constant value of the month-start-date. The INTNX function can decrement/increment different SAS variable values - check the DOC for details.

Scott Barry
SBBWorks, Inc.

SAS Language Reference: Dictionary, INTNX Function

Increments a date, time, or datetime value by a given time interval, and returns a date, time, or datetime value.
http://support.sas.com/documentation/cdl/en/lrdict/62618/HTML/default/a000212700.htm

Suggested Google advanced search argument:

proc sql select date intnx site:sas.com
DanielSantos
Barite | Level 11
If I got this right, you want to extract data from some table based on a specified month which is extracted from a parameter table. Well, you have at least two ways of doing this, both of them based on matching transformed dates.

The simple one would be to match numeric month/year:
[pre]
%Let Load_date = '01NOV2009'd;

proc sql;
select datepart(PARAM_DATE_LOW)
into :LOAD_DATE
from param_table
where PARAM_ID = 'TABLE1';

select count(*) into :SRC_REC_COUNT from SOURCE_TABLE_SRC
where month(data_column) = month(&LOAD_DATE) and
year(data_column) = year(&LOAD_DATE);
quit;
[/pre]

The other one would be to match alphas with the formatted date:
[pre]
%Let Load_date = '01NOV2009'd;

proc sql;
select datepart(PARAM_DATE_LOW)
into :LOAD_DATE
from param_table
where PARAM_ID = 'TABLE1';

select count(*) into :SRC_REC_COUNT from SOURCE_TABLE_SRC
where strip(put(DATA_COLUM,yymon6.))=
(select strip(put(datepart(PARAM_DATE_LOW),yymon6.))
from param_table
where PARAM_ID = 'TABLE1');
quit;
[/pre]

Code above not tested.

Cheers from Portugal.

Daniel Santos @ www.cgd.pt

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 2 replies
  • 1811 views
  • 0 likes
  • 3 in conversation