Hi all!
Long time programmer here, however, I am stumped!
Why the heck isn't the format retaining the zeros when I have indicated the format type as 'C'? Here is the code :
data subject(keep=siteid start label fmtname usubjid new_id);
length new_id $12;
set db.en end=end;
new_id = substr(usubjid,8,3) || substr(usubjid,4,3) ;
start = new_id;
label = usubjid;
retain fmtname "SubjectFmt" type "C";
output;
if end then do;
hlo = 'O' ;
label = 'ERROR ;
end;
run;
proc format cntlin = subject cntlout = cntlout; run;
proc format library=work; select SubjectFmt; run;
attached are exampled of the dataset and the resulting format.
Thank you!
NJGirl
Names of character formats start with $.
Why do you assign a value to TYPE but then drop the variable?
Why do you assign a vlaue to HLO but then drop the variable?
Why do never output the HLO observation?
data subject;
length fmtname $32 type $1 hlo $3 start new_id $12;
set db.en end=end;
new_id = substr(usubjid,8,3) || substr(usubjid,4,3) ;
start = new_id;
label = usubjid;
retain fmtname '$SubjectFmt' type 'C';
output;
if end then do;
hlo = 'O' ;
label = 'ERROR';
output;
end;
*keep fmtname type start label hlo ;
run;
proc format cntlin = subject cntlout = cntlout; run;
proc format library=work fmtlib; select $SubjectFmt; run;
Is usubjid a string?
Please don't hide information in office-files, many contributors won't open such files. Post data as data step using datalines, and attach screenshots using "insert photos" (the small camera icon). And don't forget to post the log as text using "insert code" so that formatting is maintained.
Names of character formats start with $.
Why do you assign a value to TYPE but then drop the variable?
Why do you assign a vlaue to HLO but then drop the variable?
Why do never output the HLO observation?
data subject;
length fmtname $32 type $1 hlo $3 start new_id $12;
set db.en end=end;
new_id = substr(usubjid,8,3) || substr(usubjid,4,3) ;
start = new_id;
label = usubjid;
retain fmtname '$SubjectFmt' type 'C';
output;
if end then do;
hlo = 'O' ;
label = 'ERROR';
output;
end;
*keep fmtname type start label hlo ;
run;
proc format cntlin = subject cntlout = cntlout; run;
proc format library=work fmtlib; select $SubjectFmt; run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.