BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Nasser_DRMCP
Lapis Lazuli | Level 10


%macro mc_delai_jours_ouvres_Z21
	(
		  p_date_debut
		, p_date_fin
		, p_flag_jour_ouvre
		, p_cod_pay_iso
		, p_cod_lng
	) ;

	%local	rc nbr_jou_ouv ;

	%let p_date_min = min(&p_date_debut,&p_date_fin) ;
	%let p_date_max = max(&p_date_debut,&p_date_fin) ;

	%if &p_date_debut <= &p_date_fin %then
		%do ;
			%let sens_chrono = 1 ; 
		%end ;
		%else %do ;
			%let sens_chrono = -1 ; 
		%end ;
	

	%let rc=%sysfunc(dosubl(%nrstr(
		proc sql noprint ;
		  select count(DAT_CVL) * &sens_chrono into :nbr_jou_ouv
		  from SBOX.&mv_prefixe_tab_dim._Z21I_5ans  
		  where DAT_CVL > &p_date_min
		  	and DAT_CVL <= &p_date_max
			and &p_flag_jour_ouvre = 'O'
			and COD_PAY_ISO = "&p_cod_pay_iso"
			and COD_LNG_RIU = "&p_cod_lng"
		;
		quit;
	))) ;

	%superq(nbr_jou_ouv)

%mend mc_delai_jours_ouvres_z21 ;

data test ;
delai = resolve(cats('%mc_delai_jours_ouvres_z21(' , '01JUL2025'd, ',' , '31JUL2025'd, ',FLG_JOU_OUV' , ',FR' , ',FR' , ')' )) ;
run ;

hello

this is the code of my macro that calculate a delay between two dates. and the result is correct. i mean, the "delai" column in the test table is 21.

but this returned delai is a string and not a numeric . so by using this kind of comparator if delai > 6 ...i get this

"ERROR: Expression using greater than (>) has components that are of different data types."

1 ACCEPTED SOLUTION

Accepted Solutions
Quentin
Super User

You could use the INPUT function to convert the value returned by RESOLVE to numeric, like below example using sashelp.class:

 

%macro try(name=) ;
  %local age ;
  %let rc=%sysfunc(dosubl(%nrstr(
 		proc sql noprint ;
		  select age into :age
      from sashelp.class 
		  where name="&name"
		;
		quit;
	))) ;

  &age
%mend ;

proc sql ;
  create table test2 as 
  select age
        ,case when input(resolve(cats('%try(name=' , name, ')' )),32.)  > 12 then 'A' else 'B' end as foo
  from sashelp.class 
   ;
quit ;

But this will run very slowly, because DOSUBL is slow (it does a lot of work), and you are calling DOSUBL for every record in in your data.

 

I can't quite follow the logic of your code, but it would probably be possible to rewrite this as a pure SQL query, and avoid use of DOSUBL.

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26

I get a different error.

 

Please show us all of the log for this program ... not just the error messages.

--
Paige Miller
Nasser_DRMCP
Lapis Lazuli | Level 10
/*  step 1 */
data test ;
delai = resolve(cats('%mc_delai_jours_ouvres_z21(' , '01JUL2025'd, ',' , '31JUL2025'd, ',FLG_JOU_OUV' , ',FR' , ',FR' , ')' )) ;
run ;
 
/*  step 2 */
proc sql;
create table test2 as
select case when resolve(cats('%mc_delai_jours_ouvres_z21(' , '01JUL2025'd, ',' , '31JUL2025'd, ',FLG_JOU_OUV' , ',FR' , ',FR' , ')' ))  > 6 
then 'O'
else 'N' end as ANO_DELAI
from test ;
quit ;
 
/*  below the log of the step 2*/
 

The SAS System Monday, August 11, 2025 10:58:00 AM

1 ;*';*";*/;quit;run;
2 OPTIONS PAGENO=MIN;
3 %LET _CLIENTTASKLABEL='MC_CALCUL_PERIODE.sas';
4 %LET _CLIENTPROCESSFLOWNAME='Standalone Not In Project';
5 %LET _CLIENTPROJECTPATH='';
6 %LET _CLIENTPROJECTPATHHOST='';
7 %LET _CLIENTPROJECTNAME='';
8 %LET _SASPROGRAMFILE='/home/ldap/mellouna/smsas/MC_CALCUL_PERIODE.sas';
9 %LET _SASPROGRAMFILEHOST='lsas1kj3.cm-cic.fr';
10
11 ODS _ALL_ CLOSE;
12 OPTIONS DEV=SVG;
13 GOPTIONS XPIXELS=0 YPIXELS=0;
14 %macro HTML5AccessibleGraphSupported;
15 %if %_SAS_VERCOMP_FV(9,4,4, 0,0,0) >= 0 %then ACCESSIBLE_GRAPH;
16 %mend;
17 FILENAME EGHTML TEMP;
18 ODS HTML5(ID=EGHTML) FILE=EGHTML
19 OPTIONS(BITMAP_MODE='INLINE')
20 %HTML5AccessibleGraphSupported
MPRINT(HTML5ACCESSIBLEGRAPHSUPPORTED): ACCESSIBLE_GRAPH
21 ENCODING='utf-8'
22 STYLE=HTMLBlue
23 NOGTITLE
24 NOGFOOTNOTE
25 GPATH=&sasworklocation
26 ;
NOTE: Writing HTML5(EGHTML) Body file: EGHTML
27
28 %saseg_interactive_begin();
MPRINT(SASEG_INTERACTIVE_BEGIN): DATA _NULL_;
MPRINT(SASEG_INTERACTIVE_BEGIN): file
"/data/sastmp1/saswork/SAS_work7A1400311831_lsas1kj3/SAS_work9D0400311831_lsas1kj3/saseg_interactive_tmp_debut.log";
MPRINT(SASEG_INTERACTIVE_BEGIN): export_date=put(date(),ddmmyy10.);
MPRINT(SASEG_INTERACTIVE_BEGIN): export_time=put(time(),time.);
MPRINT(SASEG_INTERACTIVE_BEGIN): PUT "DEBUT;mellouna;'';'/home/ldap/mellouna/smsas/MC_CALCUL_PERIODE.sas';lsas1kj3;3217457;"
export_date+(-1)";" export_time+(-1);
MPRINT(SASEG_INTERACTIVE_BEGIN): RUN;

NOTE: The file "/data/sastmp1/saswork/SAS_work7A1400311831_lsas1kj3/SAS_work9D0400311831_lsas1kj3/saseg_interactive_tmp_debut.log"
is:
Filename=/data/sastmp1/saswork/SAS_work7A1400311831_lsas1kj3/SAS_work9D0400311831_lsas1kj3/saseg_interactive_tmp_debut.log,
Owner Name=mellouna,Group Name=domain users,
Access Permission=-rw-rw-r--,
Last Modified=11Aug2025:17:24:38

NOTE: 1 record was written to the file
"/data/sastmp1/saswork/SAS_work7A1400311831_lsas1kj3/SAS_work9D0400311831_lsas1kj3/saseg_interactive_tmp_debut.log".
The minimum record length was 104.
The maximum record length was 104.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
user cpu time 0.00 seconds
system cpu time 0.00 seconds
memory 605.03k
OS Memory 59324.00k
Timestamp 08/11/2025 05:24:38 PM
Step Count 186 Switch Count 0
2 The SAS System Monday, August 11, 2025 10:58:00 AM

Page Faults 0
Page Reclaims 22
Page Swaps 0
Voluntary Context Switches 0
Involuntary Context Switches 0
Block Input Operations 0
Block Output Operations 8

MPRINT(SASEG_INTERACTIVE_BEGIN): x "cat
/data/sastmp1/saswork/SAS_work7A1400311831_lsas1kj3/SAS_work9D0400311831_lsas1kj3/saseg_interactive_tmp_debut.log >>
$SAS_APPLI/data/stats/saseg_interactive.log";
29
30 proc sql;
31 create table test2 as
32 select case when resolve(cats('%mc_delai_jours_ouvres_z21(' , '01JUL2025'd, ',' , '31JUL2025'd, ',FLG_JOU_OUV' , ',FR' ,
32 ! ',FR' , ')' )) > 6
33 then 'O'
34 else 'N' end as ANO_DELAI
35 from test ;
ERROR: Expression using greater than (>) has components that are of different data types.
NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.
36 quit ;
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE SQL used (Total process time):
real time 0.00 seconds
user cpu time 0.00 seconds
system cpu time 0.00 seconds
memory 5755.53k
OS Memory 64448.00k
Timestamp 08/11/2025 05:24:38 PM
Step Count 187 Switch Count 0
Page Faults 0
Page Reclaims 10
Page Swaps 0
Voluntary Context Switches 0
Involuntary Context Switches 0
Block Input Operations 0
Block Output Operations 0

37
38 %saseg_interactive_end();


MPRINT(SASEG_INTERACTIVE_END): DATA _NULL_;
MPRINT(SASEG_INTERACTIVE_END): file
"/data/sastmp1/saswork/SAS_work7A1400311831_lsas1kj3/SAS_work9D0400311831_lsas1kj3/saseg_interactive_tmp_fin.log";
MPRINT(SASEG_INTERACTIVE_END): export_date=put(date(),ddmmyy10.);
MPRINT(SASEG_INTERACTIVE_END): export_time=put(time(),time.);
MPRINT(SASEG_INTERACTIVE_END): PUT "FIN;mellouna;'';'/home/ldap/mellouna/smsas/MC_CALCUL_PERIODE.sas';lsas1kj3;3217457;"
export_date+(-1)";" export_time+(-1);
MPRINT(SASEG_INTERACTIVE_END): RUN;

NOTE: The file "/data/sastmp1/saswork/SAS_work7A1400311831_lsas1kj3/SAS_work9D0400311831_lsas1kj3/saseg_interactive_tmp_fin.log" is:
Filename=/data/sastmp1/saswork/SAS_work7A1400311831_lsas1kj3/SAS_work9D0400311831_lsas1kj3/saseg_interactive_tmp_fin.log,
Owner Name=mellouna,Group Name=domain users,
Access Permission=-rw-rw-r--,
Last Modified=11Aug2025:17:24:38
3 The SAS System Monday, August 11, 2025 10:58:00 AM


NOTE: 1 record was written to the file
"/data/sastmp1/saswork/SAS_work7A1400311831_lsas1kj3/SAS_work9D0400311831_lsas1kj3/saseg_interactive_tmp_fin.log".
The minimum record length was 102.
The maximum record length was 102.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
user cpu time 0.00 seconds
system cpu time 0.00 seconds
memory 717.15k
OS Memory 59324.00k
Timestamp 08/11/2025 05:24:38 PM
Step Count 188 Switch Count 0
Page Faults 0
Page Reclaims 22
Page Swaps 0
Voluntary Context Switches 0
Involuntary Context Switches 0
Block Input Operations 0
Block Output Operations 8

MPRINT(SASEG_INTERACTIVE_END): x "cat
/data/sastmp1/saswork/SAS_work7A1400311831_lsas1kj3/SAS_work9D0400311831_lsas1kj3/saseg_interactive_tmp_fin.log >>
$SAS_APPLI/data/stats/saseg_interactive.log";
39
40 %LET _CLIENTTASKLABEL=;
41 %LET _CLIENTPROCESSFLOWNAME=;
42 %LET _CLIENTPROJECTPATH=;
43 %LET _CLIENTPROJECTPATHHOST=;
44 %LET _CLIENTPROJECTNAME=;
45 %LET _SASPROGRAMFILE=;
46 %LET _SASPROGRAMFILEHOST=;
47
48 ;*';*";*/;quit;run;
49 ODS _ALL_ CLOSE;
50
51
52 QUIT; RUN;
53

Tom
Super User Tom
Super User

You appear to be trying to compare the value returned by the character function RESOLVE() to the numeric constant 6.

create table test2 as
select case 
   when resolve(...) > 6 
   then 'O'
   else 'N' 
   end as ANO_DELAI
from test 
;

If you want to convert a string into a number use the INPUT function.

when input(resolve(.....),32.) > 6 ..

 

Quentin
Super User

You could use the INPUT function to convert the value returned by RESOLVE to numeric, like below example using sashelp.class:

 

%macro try(name=) ;
  %local age ;
  %let rc=%sysfunc(dosubl(%nrstr(
 		proc sql noprint ;
		  select age into :age
      from sashelp.class 
		  where name="&name"
		;
		quit;
	))) ;

  &age
%mend ;

proc sql ;
  create table test2 as 
  select age
        ,case when input(resolve(cats('%try(name=' , name, ')' )),32.)  > 12 then 'A' else 'B' end as foo
  from sashelp.class 
   ;
quit ;

But this will run very slowly, because DOSUBL is slow (it does a lot of work), and you are calling DOSUBL for every record in in your data.

 

I can't quite follow the logic of your code, but it would probably be possible to rewrite this as a pure SQL query, and avoid use of DOSUBL.

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
  • 523 views
  • 0 likes
  • 4 in conversation