BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
afiqcjohari
Quartz | Level 8
rsubmit;
 data mytrans; 
 length TrYear 5
		  numMonth 3; 
 set db2dw.acarddet;
    TrYear = year(dTran);
		numMonth = month(dTran);
 run;
endrsubmit;
rsubmit;
proc sql;
 create table mnth_trans as
 select TrYear, numMonth, count(*) as tottxn from mytrans
 group by TrYear, numMonth;
;quit;
proc transreg data=mnth_trans;
   model identity(tottxn) = pbspline(TrYear); /* AICC criterion */
run;
endrsubmit;

What I'd like to do is combine the data step and proc sql in one procedure. 

What's the best way to do so?

Or better yet, combine all data step proc sql and proc transgreg in 1 procedure...

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

@afiqcjohari wrote:
rsubmit;
 data mytrans; 
 length TrYear 5
		  numMonth 3; 
 set db2dw.acarddet;
    TrYear = year(dTran);
		numMonth = month(dTran);
 run;
endrsubmit;
rsubmit;
proc sql;
 create table mnth_trans as
 select TrYear, numMonth, count(*) as tottxn from mytrans
 group by TrYear, numMonth;
;quit;
proc transreg data=mnth_trans;
   model identity(tottxn) = pbspline(TrYear); /* AICC criterion */
run;
endrsubmit;

What I'd like to do is combine the data step and proc sql in one procedure. 

What's the best way to do so?

Or better yet, combine all data step proc sql and proc transgreg in 1 procedure...


 

Add the word CALCULATED before you use it in the GROUP (ie group by calculated trtYear, calculated trtMonth)

Or use the calculation in the GROUP statement (ie group by year(date), month(date) )

Or use a single PROC FREQ and format the date in the procedure.

 

proc sql;
create table test as
select year(date) as Dyear, month(date) as DMonth, count(*) as Totalcount
from sashelp.stocks
group by calculated Dyear, calculated Dmonth;
quit;

proc sql;
create table test as
select year(date) as Dyear, month(date) as DMonth, count(*) as TotalCount
from sashelp.stocks
group by year(date), month(date);
quit;

proc freq data=sashelp.stocks noprint;
table date/out=want;
format date monyy7.;
run;

 

View solution in original post

5 REPLIES 5
Reeza
Super User

@afiqcjohari wrote:
rsubmit;
 data mytrans; 
 length TrYear 5
		  numMonth 3; 
 set db2dw.acarddet;
    TrYear = year(dTran);
		numMonth = month(dTran);
 run;
endrsubmit;
rsubmit;
proc sql;
 create table mnth_trans as
 select TrYear, numMonth, count(*) as tottxn from mytrans
 group by TrYear, numMonth;
;quit;
proc transreg data=mnth_trans;
   model identity(tottxn) = pbspline(TrYear); /* AICC criterion */
run;
endrsubmit;

What I'd like to do is combine the data step and proc sql in one procedure. 

What's the best way to do so?

Or better yet, combine all data step proc sql and proc transgreg in 1 procedure...


 

Add the word CALCULATED before you use it in the GROUP (ie group by calculated trtYear, calculated trtMonth)

Or use the calculation in the GROUP statement (ie group by year(date), month(date) )

Or use a single PROC FREQ and format the date in the procedure.

 

proc sql;
create table test as
select year(date) as Dyear, month(date) as DMonth, count(*) as Totalcount
from sashelp.stocks
group by calculated Dyear, calculated Dmonth;
quit;

proc sql;
create table test as
select year(date) as Dyear, month(date) as DMonth, count(*) as TotalCount
from sashelp.stocks
group by year(date), month(date);
quit;

proc freq data=sashelp.stocks noprint;
table date/out=want;
format date monyy7.;
run;

 

afiqcjohari
Quartz | Level 8
The last solution is very interesting. Where can I learn more about using format in that way?
Tom
Super User Tom
Super User

You can use the position in the column list in your GROUP BY phrase.

proc sql;
 create table mnth_trans as
  select  year(dTran) as TrYear
       ,  month(dTran) as numMonth
       , count(*) as tottxn
   from mytrans
  group by 1,2
 ;
quit;
afiqcjohari
Quartz | Level 8
This is terrific.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 5 replies
  • 17084 views
  • 4 likes
  • 4 in conversation