Hi,
Please, how should I have written this code to fix these problems?
I I use this option A the code doesn't export the TXT file , If I use OPTION B then it exports however I received a error message
" The if statement is not valid in open code" and " The end statement is not valid in open code"
I thought that option A could be right to avoid this problem however using this option is doesn't work , I mean the txt file is not created.
My SAS version is 9.04.01M4P110916
OPTION B
%if, %else, etc. only work in open code if you have SAS9.4M5 or up (see https://blogs.sas.com/content/sasdummy/2018/07/05/if-then-else-sas-programs/).
Try putting your code inside of macro and calling it.
Since SAS 9.4, %if %then %do; %end; can be used in open code.
But I guess your problem comes from the fact that you try to deal with values in macros the way one does with data step values.
The macro preprocessor is a TEXT engine, knowing only this datatype, so quotes are almost never needed.
So if you do
call symputx('export_flag','Y');
then your code should be
%if &export_flag = Y %then %do;
proc export
data=JORQUEC.TRIGGERPAYG
outfile='//SASCommon/jorquec/TRIGGERPAYG.TXT'
dbms=dlm
replace
;
delimiter='&';
run;
%end;
Please post the whole log of STEP 3, using the {i} button.
1 The SAS System 08:22 Wednesday, July 24, 2019
1 ;*';*";*/;quit;run;
2 OPTIONS PAGENO=MIN;
3 %LET _CLIENTTASKLABEL='FINAL_VERSION';
4 %LET _CLIENTPROCESSFLOWNAME='Process Flow';
5 %LET _CLIENTPROJECTPATH='D:\SAS\jorquec\Model_rebuild\2019\Manangement Console\Trigger event_PAYG.egp';
6 %LET _CLIENTPROJECTPATHHOST='RESCZKWTS004';
7 %LET _CLIENTPROJECTNAME='Trigger event_PAYG.egp';
8 %LET _SASPROGRAMFILE='';
9 %LET _SASPROGRAMFILEHOST='';
10
11 ODS _ALL_ CLOSE;
12 OPTIONS DEV=PNG;
13 GOPTIONS XPIXELS=0 YPIXELS=0;
14 FILENAME EGPDF TEMP;
15 ODS PDF(ID=EGPDF) FILE=EGPDF STYLE=Pearl;
NOTE: Writing ODS PDF(EGPDF) output to DISK destination "EGPDF", printer "PDF".
16 FILENAME EGSR TEMP;
17 ODS tagsets.sasreport13(ID=EGSR) FILE=EGSR
18 STYLE=HtmlBlue
19 STYLESHEET=(URL="file:///C:/SAS94/software/SASEnterpriseGuide/7.1/Styles/HtmlBlue.css")
20 NOGTITLE
21 NOGFOOTNOTE
22 GPATH=&sasworklocation
23 ENCODING=UTF8
24 options(rolap="on")
25 ;
NOTE: Writing TAGSETS.SASREPORT13(EGSR) Body file: EGSR
26 FILENAME EGXLSSX TEMP;
27 ODS EXCEL(ID=EGXLSSX) FILE=EGXLSSX STYLE=Excel
28 OPTIONS (
29 EMBEDDED_TITLES="no" EMBEDDED_FOOTNOTES="no"
30 );
31
32 GOPTIONS ACCESSIBLE;
ERROR: The %IF statement is not valid in open code.
33 %if &export_flag = Y %then %do;
34
35 data jorquec.TRIGGERPAYG2;
36 SET JORQUEC.TRIGGERPAYG;
37 run;
NOTE: There were 1 observations read from the data set JORQUEC.TRIGGERPAYG.
NOTE: The data set JORQUEC.TRIGGERPAYG2 has 1 observations and 4 variables.
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 564.93k
OS Memory 38604.00k
Timestamp 24/07/2019 10:25:52 AM
Step Count 15 Switch Count 2
Page Faults 0
Page Reclaims 59
Page Swaps 0
Voluntary Context Switches 12
Involuntary Context Switches 1
Block Input Operations 0
Block Output Operations 136
2 The SAS System 08:22 Wednesday, July 24, 2019
38
39 /* PROC EXPORT DATA=JORQUEC.TRIGGERPAYG
40 OUTFILE='//SASCommon/jorquec/TRIGGERPAYG.TXT'
41 DBMS=dlm
42 REPLACE;
43 delimiter='&';
44 RUN;*/
45
46 %end;
ERROR: The %END statement is not valid in open code.
47
48 GOPTIONS NOACCESSIBLE;
49 %LET _CLIENTTASKLABEL=;
50 %LET _CLIENTPROCESSFLOWNAME=;
51 %LET _CLIENTPROJECTPATH=;
52 %LET _CLIENTPROJECTPATHHOST=;
53 %LET _CLIENTPROJECTNAME=;
54 %LET _SASPROGRAMFILE=;
55 %LET _SASPROGRAMFILEHOST=;
56
57 ;*';*";*/;quit;run;
58 ODS _ALL_ CLOSE;
NOTE: ODS PDF(EGPDF) printed no output.
(This sometimes results from failing to place a RUN statement before the ODS PDF(EGPDF) CLOSE statement.)
NOTE: Writing EXCEL(EGXLSSX) file: /saswork94/SAS_work467F000089F0_czhrk-dl580nucprod-310-fe/#LN01122
59
60
61 QUIT; RUN;
You should pressure your SAS admin(s) to upgrade to the current maintenance level. Especially M5 had a lot of goodies. And with the current package, you get EG 8.1.
%if, %else, etc. only work in open code if you have SAS9.4M5 or up (see https://blogs.sas.com/content/sasdummy/2018/07/05/if-then-else-sas-programs/).
Try putting your code inside of macro and calling it.
%macro test; %if &export_flag = Y %then %do; data jorquec.TRIGGERPAYG; SET JORQUEC.TESTPAYG2; run; %end; %mend; %test;
/* Many thanks, now is fine!! */
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.