BookmarkSubscribeRSS Feed
elmendamian
Fluorite | Level 6

Hi everyone.

I'm trying to replicate a SAS 9 code in SAS Viya Data Studio to clean my data.

The SAS 9 code has a macro variable that not works in SAS Viya Data Studio (manage data). I mean, the code shows an error when I include the macro variable.
Here is a code works:

/* BEGIN data step with the output table data */
data {{_dp_outputTable}} (caslib={{_dp_outputCaslib}} promote="no");
/* Set the input set */
set {{_dp_inputTable}} (caslib={{_dp_inputCaslib}} );
/* END data step run */
      CERAPTFIS_CATEGORIA_IDCATEGOR = upcase(trimn(left(compbl(CERAPTFIS_CATEGORIA_IDCATEGOR))));
      
	  ceraptfis_fechexped = datepart(ceraptfis_fechexped);
      CERAPTFIS_VIGENCIA  = datepart(CERAPTFIS_VIGENCIA);
      CERAPTFIS_FECEXAMED = datepart(CERAPTFIS_FECEXAMED);
      CERAPTFIS_FECHCANCE = datepart(CERAPTFIS_FECHCANCE);
	  format ceraptfis_fechexped CERAPTFIS_FECEXAMED CERAPTFIS_VIGENCIA CERAPTFIS_FECHCANCE date9.;
	  if CERAPTFIS_FECHEXPED > "10dec2019"d;
run;

And here is not works code:

%let par_fecha_hoy = 10dec2019;
/* BEGIN data step with the output table data */
data {{_dp_outputTable}} (caslib={{_dp_outputCaslib}} promote="no");
/* Set the input set */
set {{_dp_inputTable}} (caslib={{_dp_inputCaslib}} );
/* END data step run */
      CERAPTFIS_CATEGORIA_IDCATEGOR = upcase(trimn(left(compbl(CERAPTFIS_CATEGORIA_IDCATEGOR))));
      
	  ceraptfis_fechexped = datepart(ceraptfis_fechexped);
      CERAPTFIS_VIGENCIA  = datepart(CERAPTFIS_VIGENCIA);
      CERAPTFIS_FECEXAMED = datepart(CERAPTFIS_FECEXAMED);
      CERAPTFIS_FECHCANCE = datepart(CERAPTFIS_FECHCANCE);
	  format ceraptfis_fechexped CERAPTFIS_FECEXAMED CERAPTFIS_VIGENCIA CERAPTFIS_FECHCANCE date9.;
	  if CERAPTFIS_FECHEXPED > "&par_fecha_hoy."d;
run;

I need to invocate lot of macros and macrovariable like SAS 9.

Anyone knows how I can use macros and macrovariables in SAS Viya Data Studio (manage data).

 

Thank you very much.

 

 

3 REPLIES 3
VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

is CERAPTFIS_FECHEXPED in your dataset a date field?

SAS dates are stored as numbers and your d. is not converting your macro to a number.

 

elmendamian
Fluorite | Level 6

Hi VDD.

Yes CERAPTFIS_FECHEXPED is a date column and his format is date9.

VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

@elmendamian you need to do something like this to convert your stringed macro date to a number that represents SAS date values.

%let mydate = 10dec2019;
data _null_;
yesterday = input("&mydate",date9.);
put yesterday;
run;

 

 

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 906 views
  • 0 likes
  • 2 in conversation