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

Hello Experts,

 

I can't resolve the error in "case" of proc sql. My code seems to be correct :

%let mois=10;
%let jour=10;
%let annee_20=2020;
%let annee_21=2021;

proc sql;
    create table Prestations_RT as
    select distinct
        is_contrat,
        datepart(d_eff_sin)        as date_sinistre            format  = ddmmyy10.,
        year(datepart(d_bilan))    as annee_bilan,
        sum(mt_brut_prest * (cd_dossier = "DCASS"))        as Mt_DC,
        sum(mt_brut_prest * (cd_dossier = "DCCCS"))        as Mt_DC_rentes,
        sum(mt_brut_prest * (cd_dossier = "RT"))        as Mt_RT,
        sum(mt_brut_prest * (cd_dossier = "RTCCS"))        as Mt_RT_rentes,
        Case
            when (mdy(01,01,2020) <= datepart(date_sinistre) <= mdy(&mois.,&jour.,&annee_20.) then "T1_2020")
            when (mdy(01,01,2021) <= datepart(date_sinistre) <= mdy(&mois.,&jour.,&annee_21.) then "T1_2021")
        end                                                as Trimestre
    from Table
    where /*substr(is_contrat,1,4) in &Liste_produits.
    and */(mdy(01,01,2020) < (datepart(date_sinistre)) < mdy(&mois..,&jour.,&annee_20.))
    and (mdy(01,01,2021) < (datepart(date_sinistre)) < mdy(&mois.,&jour.,&annee_21.))
    group by
        is_contrat,
        year(datepart(d_bilan));
quit;

I have this error all time, I don't know why.

MarieT_0-1620141734078.png

I attached the data.

 

Thank you for your help !

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

Just remove the unnecessary parentheses:

when mdy(01,01,2020) <= datepart(date_sinistre) <= mdy(&mois.,&jour.,&annee_20.) then "T1_2020"

The way you wrote it, the "then" was still part of the condition.

View solution in original post

4 REPLIES 4
Kurt_Bremser
Super User

Just remove the unnecessary parentheses:

when mdy(01,01,2020) <= datepart(date_sinistre) <= mdy(&mois.,&jour.,&annee_20.) then "T1_2020"

The way you wrote it, the "then" was still part of the condition.

SASdevAnneMarie
Barite | Level 11
Thank you, Kurt, I see !
SASdevAnneMarie
Barite | Level 11
That works !
Thank you !

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1104 views
  • 1 like
  • 2 in conversation