Hey,
So first of all i will explain you my project.
I'm tryng to know how many time take SAS for some easy calcul as median, mean and so on, for a student project.
For that i'm working on a data set of random data create by a uniform law.
So i could do those test one time for my set of data and get the time, but now i want to do this test several times on the same data set, and so i need to use a loop and the macro.
My trouble is that when i use the macro, my code is running, no break but it gives me nothing, it's look like SAS ignore everything that between the macro.
I'm surely not using it properly, but i'm stuck since few hours and i can't get what's wrong
Thanks for your help !
This is my code :
%macro main;
proc sql;
%if %sysfunc(exist(WORK.IMPORT5)) %then
%do;
drop table WORK.IMPORT5;
%end;
%if %sysfunc(exist(WORK.IMPORT5, VIEW)) %then
%do;
drop view WORK.IMPORT5;
%end;
quit;
FILENAME REFFILE FILESRVC
FOLDERPATH='/Users/olivier.perruchet@gmail.com/Zebrys'
FILENAME='integ_narr_1_norm_tiny_1.txt';
PROC IMPORT DATAFILE=REFFILE DBMS=CSV OUT=WORK.IMPORT5;
GETNAMES=no;
DATAROW=1;
RUN;
PROC CONTENTS DATA=WORK.IMPORT5;
RUN;
%DO i=1 %to 2;
%let temps_debut_mean = %sysfunc(time());
proc means data=work.import5 mean;
run;
%let temps_fin_mean = %sysfunc(time());
%let temps_debut_median = %sysfunc(time());
proc means data=work.import5 median;
run;
%let temps_fin_median = %sysfunc(time());
%let duree_mean = %sysevalf(&temps_fin_mean.-&temps_debut_mean.);
%put Durée d’exécution moyenne : &duree_mean.;
%let duree_median = %sysevalf(&temps_fin_median.-&temps_debut_median.);
%put Durée d’exécution medianne : &duree_median.;
%end ;
%mend main;
Since you seem to have unbalanced quotes (although they don't appear to be real quotes now, instead what you posted looks like the squiggly typesetting quotes that Word Processors like to replace quotes with because they think you are trying to typeset a book instead of writing a program) it might make sense to re-set your SAS session and try again. Try not to put unprotected unbalanced quotes into your code. Comments that work with unbalanced quotes in open code can cause the macro compiler to get confused.
I didn't look at what your macro does, but since all you posted was the definition, perhaps the problem is that you never actually called the macro.
%main;
In fact i didn't call it, but even so it's still not doing anything.
%macro main;
%DO i=1 %to 2;
%let temps_debut_mean = %sysfunc(time());
proc means data=work.import5 mean;
run;
%let temps_fin_mean = %sysfunc(time());
%let temps_debut_median = %sysfunc(time());
proc means data=work.import5 median;
run;
%let temps_fin_median = %sysfunc(time());
%let duree_mean = %sysevalf(&temps_fin_mean.-&temps_debut_mean.);
%put Durée d’exécution moyenne : &duree_mean.;
%let duree_median = %sysevalf(&temps_fin_median.-&temps_debut_median.);
%put Durée d’exécution medianne : &duree_median.;
%end;
%mend;
%main;
Please place this command at the beginning of your program and run it again.
options mprint symbolgen mlogic;
We need to see the LOG. Please help us out by following ALL of these steps, this will make the LOG much more readable.
Ok !
Sorry for those begginer mistake.
That is my log, and what will follow will be my code.
options mprint symbolgen mlogic;
proc sql;
%if %sysfunc(exist(WORK.IMPORT5)) %then %do;
drop table WORK.IMPORT5;
%end;
%if %sysfunc(exist(WORK.IMPORT5, VIEW)) %then %do;
drop view WORK.IMPORT5;
%end;
quit;
FILENAME REFFILE FILESRVC
FOLDERPATH='/Users/olivier.perruchet@gmail.com/Zebrys'
FILENAME='integ_narr_1_norm_tiny_1.txt';
PROC IMPORT DATAFILE=REFFILE DBMS=CSV OUT=WORK.IMPORT5;
GETNAMES=no;
DATAROW=1;
RUN;
PROC CONTENTS DATA=WORK.IMPORT5;
RUN;
%macro main;
%DO i=1 %to 2;
%let temps_debut_mean = %sysfunc(time());
proc means data=work.import5 mean;
run;
%let temps_fin_mean = %sysfunc(time());
%let temps_debut_median = %sysfunc(time());
proc means data=work.import5 median;
run;
%let temps_fin_median = %sysfunc(time());
%let duree_mean = %sysevalf(&temps_fin_mean.-&temps_debut_mean.);
%put Durée d’exécution moyenne : &duree_mean.;
%let duree_median = %sysevalf(&temps_fin_median.-&temps_debut_median.);
%put Durée d’exécution medianne : &duree_median.;
%end;
%mend;
%main;
1 %studio_hide_wrapper; 2 OPTIONS NOSYNTAXCHECK; 3 TITLE; 4 FOOTNOTE; 5 DATA _NULL_; 6 RUN; 7 OPTIONS VALIDVARNAME=ANY; 8 OPTIONS VALIDMEMNAME=EXTEND; 9 ODS _ALL_ CLOSE; 10 11 OPTIONS NOSYNTAXCHECK; 12 DATA _NULL_; 13 LENGTH RC 4; 14 %let TWORKLOC="%sysfunc(getoption(work))"; 15 RC=DLGCDIR(&TWORKLOC); 16 RUN; 17 OPTIONS NOSYNTAXCHECK; 18 FILENAME _HTMLOUT TEMP; 19 FILENAME _LISTOUT TEMP; 20 FILENAME _GSFNAME TEMP; 21 FILENAME _DATAOUT TEMP; 22 %LET SYSCC=0; 23 %LET _CLIENTAPP = %NRQUOTE(%NRSTR(SAS Studio)); 24 %LET _CLIENTAPPABBREV = %NRQUOTE(%NRSTR(Studio)); 25 %LET _CLIENTAPPVERSION=5.2; 26 %LET _CLIENTVERSION=5.2; 27 %LET _SASSERVERNAME = %NRQUOTE(%NRSTR(sasserver)); 28 %LET _SASHOSTNAME = %NRQUOTE(%NRSTR(sasserver)); 29 %LET _SASPROGRAMFILEHOST = %NRQUOTE(%NRSTR(sasserver)); 30 %LET _CLIENTUSERID = %NRQUOTE(%NRSTR(olivier.perruchet@gmail.com)); 31 %LET _CLIENTUSERNAME = %NRQUOTE(%NRSTR(u48668032 31 ! )); 32 %LET CLIENTMACHINE = %NRQUOTE(%NRSTR(176.175.145.149)); 33 %LET _CLIENTMACHINE = %NRQUOTE(%NRSTR(176.175.145.149)); 34 %LET _CLIENTMODE = %NRQUOTE(%NRSTR(viya)); 35 %let SASWORKLOCATION="%sysfunc(getoption(work))/"; 36 FILENAME _CWD &SASWORKLOCATION; 37 DATA _NULL_; 38 CALL SYMPUT('_SASWORKINGDIR',PATHNAME('_CWD')); 39 RUN; 40 FILENAME _CWD; 41 %LET _SASPROGRAMFILE = %NRQUOTE(%NRSTR()); 42 %LET _BASEURL = %NRQUOTE(%NRSTR(http://pdcesx20067.exnet.sas.com/SASStudioV/)); 43 %LET _EXECENV = %NRQUOTE(%NRSTR(SASStudio;)); 44 DATA _NULL_; 45 LENGTH RC $255; 46 CALL SYMPUT("GRAPHINIT",""); 47 CALL SYMPUT("GRAPHTERM",""); 48 RC=TSLVL('SASXGOPT','N'); 49 _ERROR_=0; 50 IF (RC^=' ') THEN DO; 51 CALL SYMPUT("GRAPHINIT","GOPTIONS RESET=ALL GSFNAME=_GSFNAME;"); 52 CALL SYMPUT("GRAPHTERM","GOPTIONS NOACCESSIBLE;"); 53 END; 54 RUN; 55 DATA _NULL_; 56 LENGTH RC 4; 57 RC=SYSPROD("PRODNUM002"); 58 IF (RC^=1) THEN DO; 59 CALL SYMPUT("GRAPHINIT",""); 60 CALL SYMPUT("GRAPHTERM",""); 61 END; 62 RUN; 63 %LET _DATAOUT_MIME_TYPE=; 64 %LET _DATAOUT_NAME=; 65 %LET _DATAOUT_TABLE=; 66 %LET _DATAOUT_URL=; 67 %SYMDEL _DATAOUT_MIME_TYPE _DATAOUT_NAME _DATAOUT_URL _DATAOUT_TABLE; 68 %LET _SASWS_ = %BQUOTE(%sysfunc(getoption(work))); 69 %LET _SASWSTEMP_ = %BQUOTE(%sysfunc(getoption(work))); 70 ODS LISTING CLOSE; 71 OPTIONS PRINTERPATH=PDF; 72 ODS AUTONAVIGATE OFF; 73 ODS GRAPHICS ON; 74 ODS HTML5 (ID=WEB) DEVICE=PNG GPATH="&_SASWSTEMP_" PATH="&_SASWSTEMP_" ENCODING=utf8 FILE=_HTMLOUT 74 ! (TITLE='Results:Programme_Main.sas') STYLE=Illuminate OPTIONS(BITMAP_MODE='INLINE' OUTLINE='ON' SVG_MODE='INLINE' 74 ! CSS_PREFIX='.ods_471baa99-5a62-439a-b573-311e38057059' BODY_ID='div_471baa99-5a62-439a-b573-311e38057059' ); 75 ODS LISTING FILE=_LISTOUT; 76 &GRAPHINIT; 77 OPTIONS FIRSTOBS=1; 78 OPTIONS OBS=MAX; 79 OPTIONS DTRESET DATE NUMBER; 80 OPTIONS DEVICE=PNG; 81 %studio_restore_wrapper; 82 /* Generated Code (IMPORT) */ 83 /* Source File: integ_narr_1_norm_tiny_1.txt */ 84 /* Source Path: /Users/olivier.perruchet@gmail.com/Zebrys/integ_narr_1_norm_tiny_1.txt */ 85 /* Code generated on: May 5, 2020, 4:02:18 */ 86 options mprint symbolgen mlogic; 87 proc sql; 88 %if %sysfunc(exist(WORK.IMPORT5)) %then %do; 89 drop table WORK.IMPORT5; 90 %end; 91 %if %sysfunc(exist(WORK.IMPORT5, VIEW)) %then %do; 92 drop view WORK.IMPORT5; 93 %end; 94 quit; 95 96 FILENAME REFFILE FILESRVC 97 FOLDERPATH='/Users/olivier.perruchet@gmail.com/Zebrys' 98 FILENAME='integ_narr_1_norm_tiny_1.txt'; 99 100 PROC IMPORT DATAFILE=REFFILE DBMS=CSV OUT=WORK.IMPORT5; 101 GETNAMES=no; 102 DATAROW=1; 103 RUN; 104 105 PROC CONTENTS DATA=WORK.IMPORT5; 106 RUN; 107 108 %macro main; 109 %DO i=1 %to 2; 110 %let temps_debut_mean = %sysfunc(time()); 111 112 proc means data=work.import5 mean; 113 run; 114 115 %let temps_fin_mean = %sysfunc(time()); 116 %let temps_debut_median = %sysfunc(time()); 117 118 proc means data=work.import5 median; 119 run; 120 121 %let temps_fin_median = %sysfunc(time()); 122 %let duree_mean = %sysevalf(&temps_fin_mean.-&temps_debut_mean.); 123 %put Durée d’exécution moyenne : &duree_mean.; 124 %let duree_median = %sysevalf(&temps_fin_median.-&temps_debut_median.); 125 %put Durée d’exécution medianne : &duree_median.; 126 %end; 127 %mend; 128 129 %main; 130 131 %studio_hide_wrapper; 132 ODS HTML CLOSE; 133 &GRAPHTERM; ;*';*";*/;RUN;QUIT; 134 QUIT;RUN; 135 ODS HTML5 (ID=WEB) CLOSE; 136 137 ODS LISTING CLOSE; 138 FILENAME _GSFNAME; 139 DATA _NULL_; 140 RUN; 141 %studio_restore_wrapper; 142
Since you seem to have unbalanced quotes (although they don't appear to be real quotes now, instead what you posted looks like the squiggly typesetting quotes that Word Processors like to replace quotes with because they think you are trying to typeset a book instead of writing a program) it might make sense to re-set your SAS session and try again. Try not to put unprotected unbalanced quotes into your code. Comments that work with unbalanced quotes in open code can cause the macro compiler to get confused.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Early bird rate extended! Save $200 when you sign up by March 31.
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.