Date: Sun, 22 Jul 2007 20:14:58 +0200
Reply-To: Rune Runnestø <rune@FASTLANE.NO>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Rune Runnestø <rune@FASTLANE.NO>
Subject: Using the put-statement to create a code file for use with
%include
/*
The first datastep generaste the table __KODETABELL which
contains metadata information to create three other tables.
In the next three datasteps I create these tables by hardcoding them.
In the data _null_ step I try to create code that can create the
three data steps. The %INCLUDE is intended to execute that code
and create them.
But the result of the data _null_ step is not what I expected.
I guess there must be something logically wrong with the code, but
can't see what it is.
*/
data __kodetabell;
attrib
Feltnamn length = $30
Feltverdi length = $5
Forklaring length = $80
;
infile datalines truncover;
input
@01 Feltnamn $30.
@40 Feltverdi $5.
@50 Forklaring $80.
;
datalines;
AKSJETYPE 03 A
AKSJETYPE 04 B
KLAGEINSTANS_ANS . Ikke utfylt
KODE17_ANS . Ikke utfylt
KODE17_ANS 17 Tilleggsskatt
;
run;
data tp07_ktab_AKSJETYPE;
attrib
feltverdi length = $5
forklaring length = $15
;
infile cards;
input
@1 Feltverdi $5.
@10 Forklaring $15.
;
datalines;
03 A
04 B
;
run;
data tp07_ktab_KLAGEINSTANS_ANS;
attrib
feltverdi length = $5
forklaring length = $15
;
infile cards;
input
@1 Feltverdi $5.
@10 Forklaring $15.
;
datalines;
. Ikke utfylt
;
run;
data tp07_ktab_KODE17_ANS;
attrib
feltverdi length = $5
forklaring length = $15
;
infile cards;
input
@1 Feltverdi $5.
@10 Forklaring $15.
;
datalines;
. Ikke utfylt
17 Tilleggsskatt
;
run;
proc sql;
drop table tp07_ktab_aksjetype;
drop table tp07_ktab_KODE17_ANS;
drop table tp07_ktab_KLAGEINSTANS_ANS;
quit;
filename lkf_tp07 "d:\temp\kodetable.sas";
data _null_;
set __kodetabell;
file lkf_tp07 noprint;
if first.feltnamn then do;
a = 'data tp07_ktab_' || compress(feltnamn) || ';' ;
b = 'attrib' ;
c = compress(feltnamn) || 'length = $5' ;
d = 'forklaring length = $80' ;
e = ';' ;
f = 'infile cards;' ;
g = 'input';
h = '@1 ' || compress(feltnamn) || '$5.' ;
i = '@7 forklaring $80.';
j = ';' ;
k = 'datalines;' ;
put @01 a;
put @04 b;
put @07 c;
put @07 d;
put @04 e;
put @04 f;
put @04 g;
put @07 h;
put @07 i;
put @04 j;
put @01k;
end;
put @1 Feltverdi @10 forklaring;
if last.feltnamn then do;
a2 = ';' ;
b2 = 'run;' ;
put @04 a2;
put @01 b2;
end;
run;
%include lkf_tp07;
/*
Only this comes in the file d:\temp\kodetable.sas
03 A
04 B
Ikke utfylt
Ikke utfylt
17 Tilleggsskatt
*/
Regards, Rune