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
... View more