I carefully read and executed the steps outlined in uploading and accessing local data. My problem now is how to get previously written code to work. I'm enclosing a file which includes server files and folders, source code, and log of my attempt. Can you help? Thank you.
Sincerely,
Mary A. Marion
On SAS on Demand for Academics, all files accessible to you reside in your home directory, so the %LET needs to be this:
%let dirdata=/home/u50158717/sasmacs2;
and the data step code would be
data sasmacs2.id;
infile "&dirdata./id.txt";
input id $;
run;
Note that I added a period in the DATA statement, and changed the place where the slash is used, for better readability.
Please post logs by copy/pasting into a window opened with the </> button, and code by using the "little running man" button right next to it.
Your pdf won't even open with the website's previewer, so I will not download it.
These buttons are right above the main posting window:
The 7th is for logs, the 8th for code.
I carefully read and executed the steps outlined in uploading and accessing local data. My problem now is how to get previously written code to work. I'm enclosing a file which includes server files and folders, source code, and log of my attempt.
My data is under directory sasmacs2 and is called id.txt. SAS Code is given below:
%let dirdata=/folders/myshortcuts/sasmacs2/; libname sasmacs2 "/home/u50158717/sasmacs2"; data sasmacs2 id; infile "&dirdata.id.txt"; input id $; run; %include "sasmacs2.id.txt"; proc print; run;
Log file is below:
%let dirdata=/folders/myshortcuts/sasmacs2/; libname sasmacs2 "/home/u50158717/sasmacs2"; data sasmacs2.id; infile "&dirdata.id.txt"; input id $; run; %include 'sasmacs2.id.txt'; proc print; run; ======================================================================================== 1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK; SYMBOLGEN: Macro variable _SASWSTEMP_ resolves to /home/u50158717/.sasstudio/.images/aff1c02d-214e-40da-8cf6-07ec51ea 4f19 SYMBOLGEN: Some characters in the above value which were subject to macro quoting have been unquoted for printing. SYMBOLGEN: Macro variable GRAPHINIT resolves to GOPTIONS RESET=ALL GSFNAME=_GSFNAME; 72 73 %let dirdata=/folders/myshortcuts/sasmacs2/; 74 libname sasmacs2 "/home/u50158717/sasmacs2"; NOTE: Libref SASMACS2 was successfully assigned as follows: Engine: V9 Physical Name: /home/u50158717/sasmacs2 75 data sasmacs2.id; SYMBOLGEN: Macro variable DIRDATA resolves to /folders/myshortcuts/sasmacs2/ 76 infile "&dirdata.id.txt"; 77 input id $; 78 run; ERROR: Physical file does not exist, /folders/myshortcuts/sasmacs2/id.txt. NOTE: The SAS System stopped processing this step because of errors. WARNING: The data set SASMACS2.ID may be incomplete. When this step was stopped there were 0 observations and 1 variables. ======================================================================================== 79 80 %include 'sasmacs2.id.txt'; WARNING: Physical file does not exist, /pbr/biconfig/940/Lev1/SASApp/sasmacs2.id.txt. ERROR: Cannot open %INCLUDE file sasmacs2.id.txt. 81 proc print; 82 run; NOTE: No observations in data set SASMACS2.ID.
Can you help? I want to do two ways ( also using the include statement ).
Sincerely,
Mary A. Marion
Note:
id file is a list of id's beginning with a
a
b
c
d
e
f
On SAS on Demand for Academics, all files accessible to you reside in your home directory, so the %LET needs to be this:
%let dirdata=/home/u50158717/sasmacs2;
and the data step code would be
data sasmacs2.id;
infile "&dirdata./id.txt";
input id $;
run;
Note that I added a period in the DATA statement, and changed the place where the slash is used, for better readability.
Please post logs as requested. The main posting window destroys the horizontal positioning of the ERROR markers (among other things).
Since your code as posted:
filename id "&dirdata./id.txt";
%inc id;
is correct, the code you have before that is also important, as it might be the reason for the problem. So please post the whole code and log of that, so we can see the context.
OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK; 72 73 options mrecall; 74 %macro CreateIdVariables(data,obs,cancel,noobs); 75 *Creates id variables, obs=# of observations to be read in, 76 noobs=indicator as to whether obs # will be included in 76 ! output; 77 78 %let dirdata=/home/u50158717/sasmacs2; 79 data sasmacs2.id; 80 infile "&dirdata./id.txt"; 81 input id $; run; 82 83 data id; set sasmacs2.id (firstobs=1 obs=&obs); run; 84 options varlenchk=nowarn; 85 data &data; merge id &data; run; 86 options nocenter; 87 proc print data=&data &noobs; 88 title "Datafile &data with ID added"; 89 run &cancel; title; 90 data _null_; 91 call symput('NoObs',trim(left(put(&obs,3.0)))); 92 run; quit; 93 data idtemp; set &data; keep id; run; 94 %mend CreateIdVariables; 95 96 %CreateIdVariables(new,4, ,noobs) NOTE: The infile "/home/u50158717/sasmacs2/id.txt" is: Filename=/home/u50158717/sasmacs2/id.txt, Owner Name=u50158717,Group Name=oda, Access Permission=-rw-r--r--, Last Modified=10Jan2021:05:00:22, File Size (bytes)=10726 NOTE: 3576 records were read from the infile "/home/u50158717/sasmacs2/id.txt". The minimum record length was 1. The maximum record length was 1. NOTE: The data set SASMACS2.ID has 3576 observations and 1 variables. NOTE: DATA statement used (Total process time): real time 0.02 seconds user cpu time 0.00 seconds system cpu time 0.00 seconds memory 809.37k OS Memory 33704.00k Timestamp 01/10/2021 04:55:37 PM Step Count 276 Switch Count 2 Page Faults 0 Page Reclaims 131 Page Swaps 0 Voluntary Context Switches 49 Involuntary Context Switches 0 Block Input Operations 0 Block Output Operations 264 NOTE: There were 4 observations read from the data set SASMACS2.ID. NOTE: The data set WORK.ID has 4 observations and 1 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 941.56k OS Memory 33964.00k Timestamp 01/10/2021 04:55:37 PM Step Count 277 Switch Count 2 Page Faults 0 Page Reclaims 151 Page Swaps 0 Voluntary Context Switches 21 Involuntary Context Switches 0 Block Input Operations 288 Block Output Operations 264 NOTE: There were 4 observations read from the data set WORK.ID. NOTE: There were 4 observations read from the data set WORK.NEW. NOTE: The data set WORK.NEW has 4 observations and 3 variables. NOTE: DATA statement used (Total process time): real time 0.00 seconds user cpu time 0.00 seconds system cpu time 0.01 seconds memory 1287.15k OS Memory 34224.00k Timestamp 01/10/2021 04:55:37 PM Step Count 278 Switch Count 2 Page Faults 0 Page Reclaims 166 Page Swaps 0 Voluntary Context Switches 9 Involuntary Context Switches 0 Block Input Operations 0 Block Output Operations 264 NOTE: There were 4 observations read from the data set WORK.NEW. NOTE: PROCEDURE PRINT used (Total process time): real time 0.02 seconds user cpu time 0.03 seconds system cpu time 0.00 seconds memory 2375.68k OS Memory 34216.00k Timestamp 01/10/2021 04:55:37 PM Step Count 279 Switch Count 1 Page Faults 0 Page Reclaims 140 Page Swaps 0 Voluntary Context Switches 5 Involuntary Context Switches 0 Block Input Operations 0 Block Output Operations 8 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 463.59k OS Memory 34212.00k Timestamp 01/10/2021 04:55:37 PM Step Count 280 Switch Count 0 Page Faults 0 Page Reclaims 72 Page Swaps 0 Voluntary Context Switches 0 Involuntary Context Switches 0 Block Input Operations 0 Block Output Operations 0 NOTE: There were 4 observations read from the data set WORK.NEW. NOTE: The data set WORK.IDTEMP has 4 observations and 1 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 938.25k OS Memory 34732.00k Timestamp 01/10/2021 04:55:37 PM Step Count 281 Switch Count 2 Page Faults 0 Page Reclaims 125 Page Swaps 0 Voluntary Context Switches 9 Involuntary Context Switches 0 Block Input Operations 0 Block Output Operations 264 97 98 * Alternate Approach using include statement 99 *1] working code 100 %include("&dirdata./id.txt"); 101 data new2; merge id new; run; NOTE: There were 4 observations read from the data set WORK.ID. NOTE: There were 4 observations read from the data set WORK.NEW. NOTE: The data set WORK.NEW2 has 4 observations and 3 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 1396.18k OS Memory 34992.00k Timestamp 01/10/2021 04:55:37 PM Step Count 282 Switch Count 2 Page Faults 0 Page Reclaims 163 Page Swaps 0 Voluntary Context Switches 11 Involuntary Context Switches 0 Block Input Operations 0 Block Output Operations 264 102 proc print; 103 run; NOTE: There were 4 observations read from the data set WORK.NEW2. NOTE: PROCEDURE PRINT used (Total process time): real time 0.01 seconds user cpu time 0.02 seconds system cpu time 0.00 seconds memory 859.75k OS Memory 34472.00k Timestamp 01/10/2021 04:55:37 PM Step Count 283 Switch Count 0 Page Faults 0 Page Reclaims 70 Page Swaps 0 Voluntary Context Switches 0 Involuntary Context Switches 0 Block Input Operations 0 Block Output Operations 0 104 105 *2] non working 106 %let dirdata=/home/u50158717/sasmacs2; 107 %include "&dirdata./id.txt"; 108 +a _ 180 ERROR 180-322: Statement is not valid or it is used out of proper order. 3684 %myprn(sasmacs2.id,id,1,4); NOTE: There were 4 observations read from the data set SASMACS2.ID. NOTE: PROCEDURE PRINT used (Total process time): real time 0.00 seconds user cpu time 0.01 seconds system cpu time 0.01 seconds memory 498.78k OS Memory 34728.00k Timestamp 01/10/2021 04:55:37 PM Step Count 284 Switch Count 0 Page Faults 0 Page Reclaims 63 Page Swaps 0 Voluntary Context Switches 2 Involuntary Context Switches 0 Block Input Operations 0 Block Output Operations 0 3685 3686 *3] non working 3687 filename id "&dirdata./id.txt"; 3688 %inc id; 3689 +a _ 180 ERROR 180-322: Statement is not valid or it is used out of proper order. 7265 data new2; 7265 ! merge id new; _____ 180 ERROR 180-322: Statement is not valid or it is used out of proper order. 7266 proc print; 7267 run; NOTE: There were 4 observations read from the data set WORK.NEW2. NOTE: PROCEDURE PRINT used (Total process time): real time 0.01 seconds user cpu time 0.01 seconds system cpu time 0.00 seconds memory 527.25k OS Memory 34728.00k Timestamp 01/10/2021 04:55:37 PM Step Count 285 Switch Count 0 Page Faults 0 Page Reclaims 67 Page Swaps 0 Voluntary Context Switches 0 Involuntary Context Switches 1 Block Input Operations 0 Block Output Operations 0 7268 7269 *error 180-322 statement is not valid 7270 7271 7272 7273 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK; 7274 ODS HTML CLOSE; 7275 &GRAPHTERM; ;*';*";*/;RUN;QUIT; 7276 QUIT;RUN; 7277 ODS HTML5 (ID=WEB) CLOSE; 7278 7279 ODS RTF (ID=WEB) CLOSE; 7280 ODS PDF (ID=WEB) CLOSE; NOTE: ODS PDF(WEB) printed 4 pages to /saswork/SAS_work539D0001D89E_odaws04-usw2.oda.sas.com/#LN00805. 7281 FILENAME _GSFNAME; NOTE: Fileref _GSFNAME has been deassigned. 7282 DATA _NULL_; 7283 RUN; NOTE: DATA statement used (Total process time): real time 0.00 seconds user cpu time 0.01 seconds system cpu time 0.00 seconds memory 467.25k OS Memory 31144.00k Timestamp 01/10/2021 04:55:37 PM Step Count 286 Switch Count 0 Page Faults 0 Page Reclaims 24 Page Swaps 0 Voluntary Context Switches 0 Involuntary Context Switches 0 Block Input Operations 0 Block Output Operations 0 7284 OPTIONS NOTES STIMER SOURCE SYNTAXCHECK; 7285
DATA NEW;
INPUT X Y;
CARDS;
1 2
3 4
5 6
7 8
;
%include '/home/rrstartbuck49/macros/*.sas' ;
%MYPRINT(NEW);options mrecall;
%macro CreateIdVariables(data,obs,cancel,noobs);
*Creates id variables, obs=# of observations to be read in,
noobs=indicator as to whether obs # will be included in output;
%let dirdata=/home/u50158717/sasmacs2;
data sasmacs2.id;
infile "&dirdata./id.txt";
input id $; run;
data id; set sasmacs2.id (firstobs=1 obs=&obs); run;
options varlenchk=nowarn;
data &data; merge id &data; run;
options nocenter;
proc print data=&data &noobs;
title "Datafile &data with ID added";
run &cancel; title;
data _null_;
call symput('NoObs',trim(left(put(&obs,3.0))));
run; quit;
data idtemp; set &data; keep id; run;
%mend CreateIdVariables;
%CreateIdVariables(new,4, ,noobs)
* Alternate Approach using include statement
*1] working code
%include("&dirdata./id.txt");
data new2; merge id new; run;
proc print;
run;
*2] non working
%let dirdata=/home/u50158717/sasmacs2;
%include "&dirdata./id.txt";
%myprn(sasmacs2.id,id,1,4);
*3] non working
filename id "&dirdata./id.txt";
%inc id;
data new2; merge id new; run;
proc print;
run;
*error 180-322 statement is not valid
RESULTS:
Datafile new with ID added id X Y a 1 2 b 3 4 c 5 6 d 7 8 Obs id X Y 1 a 1 2 2 b 3 4 3 c 5 6 4 d 7 8 Obs id 1 a 2 b 3 c 4 d Obs id X Y 1 a 1 2 2 b 3 4 3 c 5 6 4 d 7 8
You CANNOT use a data file as program code.
Here:
105 *2] non working
106 %let dirdata=/home/u50158717/sasmacs2;
107 %include "&dirdata./id.txt";
108 +a
_
180
ERROR 180-322: Statement is not valid or it is used out of proper order.
the text from the file is included into the running program, but there is no statement "A" in SAS, so you rightfully get a syntax error. This ERROR encompasses everything up to the next semicolon (and that means the whole text file and the next statement in your code), from where SAS tries to make sense of the following code, but that fails because a correct statement was "out-errored" by this. E.g. a DATA statement is not recognized, and the whole data step code following it becomes syntactically invalid.
Why do you start comments and not end them?
* Alternate Approach using include statement
The comment statement that starts with * has to end with a semi-colon.
Also if you want to comment out macro code it is better to use either macro comments that start with %* and end with semi-colon.
Or use block comments that start with /* and end with */ .
I also strongly (and I mean STRONGLY) recommend that you stop meddling with macro code for the time being, and get your code to run with simple Base SAS language for a single instance. Only when this is successful (no ERRORs, no WARNINGs and resulting in the expected datasets/output) can you start to make the code dynamic.
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!
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.
Ready to level-up your skills? Choose your own adventure.