- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I have a sas code like below :
proc sort data=MIS_TABLES_SEG_F out=MIS_TABLES_SEG_F1;
by AB_IP_SICSID Valdate;
run;
Data MIS_TABLES_SEG_F2;
set MIS_TABLES_SEG_F1;
by AB_IP_SICSID Valdate;
if first.valdate then do;
Gross_EPI_initial_Fx1=Gross_EPI_initial_Fx1;
Gross_Ult_Prem_Fx1=Gross_Ult_Prem_Fx1;
Gross_Unearn_IBNR_Fx1=Gross_Unearn_IBNR_Fx1;
else do;
Gross_EPI_initial_Fx1=.;
Gross_Ult_Prem_Fx1=.;
RUN;
i need to convert this to sql query.
COuld you please help?
Thanks,
CHithra
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi @chithra ,
Did you try something like this (I don't see your data so consider below as a pseudo-code):
proc sql;
create table MIS_TABLES_SEG_F2 as
select * , /* list comumns you need */
case when (valdate = min(valdate)) then Gross_EPI_initial_Fx1
else . end as Gross_EPI_initial_Fx1,
.... /* and same for other */
from MIS_TABLES_SEG_F1
group by AB_IP_SICSID
order by AB_IP_SICSID, Valdate
;
quit;
All the best
Bart
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug
"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings
SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Your data step code can be simplified to
data MIS_TABLES_SEG_F2;
set MIS_TABLES_SEG_F1;
by AB_IP_SICSID Valdate;
if not first.valdate then do;
Gross_EPI_initial_Fx1 = .;
Gross_Ult_Prem_Fx1 = .;
end;
run;
You seem to rely on an implicit order within a valdate group here, if that is true, what is it?
@chithra wrote:
Hi,
I have a sas code like below :
proc sort data=MIS_TABLES_SEG_F out=MIS_TABLES_SEG_F1;
by AB_IP_SICSID Valdate;
run;
Data MIS_TABLES_SEG_F2;
set MIS_TABLES_SEG_F1;
by AB_IP_SICSID Valdate;
if first.valdate then do;
Gross_EPI_initial_Fx1=Gross_EPI_initial_Fx1;
Gross_Ult_Prem_Fx1=Gross_Ult_Prem_Fx1;
Gross_Unearn_IBNR_Fx1=Gross_Unearn_IBNR_Fx1;else do;
Gross_EPI_initial_Fx1=.;
Gross_Ult_Prem_Fx1=.;RUN;
i need to convert this to sql query.
COuld you please help?
Thanks,
CHithra
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi Team,
Can you pls. help me in converting this sas code to sql. I 've been struggling to find the appropriate content by my own, however no success...
proc sql;
create table active_acct2 as
select &run_month. as period,
atv.applid,
atv.acctnbr,
case when atv.applid='IN' then substr(atv.acctnbr,1,findw(atv.acctnbr,scan(atv.acctnbr,-1))-2)
else atv.acctnbr end as acctnbr_alt,
act.opendt,
act.deptid,
act.prod,
act.cif,
cli.bsa_risk_rating,
cli.customer_category,
cli.shortname
from active_acct atv
left join abc_account5 act
on atv.applid=act.applid and
atv.acctnbr=act.acctnbr
left join dim_client cli
on act.cif=cli.cif
order by applid, acctnbr;
quit;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
What you've posted is SAS-specific SQL already. You will have to provide more details of what your exact problem is. If you are getting errors in your SAS log you need to post them.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you for looking into. I'm mainly worried on how to translate this line specifically.
case when atv.applid='IN' then substr(atv.acctnbr,1,findw(atv.acctnbr,scan(atv.acctnbr,-1))-2). What i mean is how to translate substr, findw and scan in the code.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Translate into what? Does it work correctly already?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
This is SQL code, so where is the need to "translate"?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
How can i convert the case statement with these SAS specific codes to sql server codes is my question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Are you going to use SQL Passthru then? That's the only way you can run SQL Server-specific code in SAS. Have you tested the SQL as it is against SQL Server to see if it works? There's no problem running SAS functions in SQL against SQL Server if you use an "implicit SQL" connection.