Formatierung ändern

Ich verwende eine Formattabelle welche die Ausprägung einer Variable enthält Field = $4.0 (alphanumerisch 4stellig, linksbündig). Jetzt möchte ich aber die Werte in der zu formatierenden Spalte mit 0 auffüllen (Format z4.). Dies mach ich über ein Makro indem ich das Feld neu mit einem Format belege.

%let frmt=;
data _null_;
set FormatTable;
where name = "Art";
frmt = TRANWRD(frmt,'24'x,"z"); * ersetze $ mit z;
call symput ("frmt", frmt);

run;

data NewFormat;
format Art2 &frmt.;
run;

Kurioserweise erstellt SAS mir eine neue Variable rechtsbündig numerisch mit Null vorneweg, was theoretisch unmöglich ist. Denn wie wir wissen gibt es numerische werte nicth mit null beginnend.

Wie kann ich nun aus einem Feld, welches mit $4.0 definiert ist und Werte wie 1,2,3,... enthält, ein Feld 4 stellig machen, welches alphanumerisch ist und 0001,0002,0003,... enthält.

Das Mapping siehe Anhang ist so natürlich unmöglich.

Danke, Sven

Kombination von put und input

Hallo Sven,

probiere es mal so:


data a;
format a $4.;
a=
'1';
a=put(input(a,
4.),z4.);
run;

Falls ich dich richtig verstanden habe. Das Format von a ist natürlich immer noch ein $4., nur mit voranstehenden Nullen.

Gruß
Wolfgang

Halbe Lösung

Hallo Wolfgang,

Dein Vorschlag erst die Variable in numerisch und dann wieder zurück formatieren, geht natürlich auch. Problem ist jedoch, da ich einige Felder so konvertiere, daß er Felder mit Buchstaben auch konvertiert und die enthalten dann nen Missing value. Muß also noch nen Schritt er, wo der Zelleninhalt nach Buchstaben gescannt wird.

%let num=;
%let alpha=;
%let frmt=;

data _null_;
set Formattabelle;
where substr(name,3) = "variable";
if substr(frmt,1,1) eq "$" then do;
call symput ("alpha", TRANWRD(frmt,'24'x,"z"));
call symput ("num", TRANWRD(frmt,'24'x,""));
call symput ("frmt", frmt);
end; else call symput ("frmt", frmt);

%put α
%put #
%put &frmt;
run;

data Tabelle;
set Tabelle;
format variable &frmt.;

variable = put(input(variable,&num.),&alpha.);
output variable;
run;

Gruß, Sven