Hi Experts,
There is a challenging query for me though may not be for SAS experts... ![]()
proc sql;
create table tab1 as
select objects, count(*) as xxxxxxxxxxx from tab2
WHERE
DATESAS >= intnx('month',today(),-1,'begin') and
DATESAS <= intnx('month',today(),-1,'end')
group by objects;
quit;
In place of xxxxxxxxx I need to display it as Jun_Count ( when I execute this query in July...)
and when I execute this query in August, it should display Jul_Count and so on...
Experts , pls help!
Should be :
%let mon=%sysfunc(intnx(month,%sysfunc(today()),-1) ,monname3.);
%put &mon ;
proc sql;
create table tab1 as
select objects, count(*) as &mon._Count from tab2
WHERE
DATESAS >= intnx('month',today(),-1,'begin') and
DATESAS <= intnx('month',today(),-1,'end')
group by objects;
quit;
Ksharp
Ksharp, u r great! it works ! Thanks!
Then please mark Ksharp's answer as correct so this question appears as answered and you're also giving credit to the one who deserves it.
I don't know that you can omit %sysfunc(putn()), what is going on here? can you explain it a little more?
Thanks in advance,
Haikuo
NM, got my answer: SAS(R) 9.3 Macro Language: Reference
I have to remember RTFM all the time.
Hi jack
Try this
data _nall_;
x =intnx('month',today(),-1,'begin');
x1 = compress(catx('',propcase(substr(put(x,date9.),3,3)),'_','Count'));
call symput('xxxxxxxxxxx',x1);
run;
proc sql;
create table tab1 as
select objects, count(*) as &xxxxxxxxxxx from tab2
WHERE
DATESAS >= intnx('month',today(),-1,'begin') and
DATESAS <= intnx('month',today(),-1,'end')
group by objects;
quit;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.