BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
NJGIRL
Obsidian | Level 7

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

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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;

 

View solution in original post

6 REPLIES 6
NJGIRL
Obsidian | Level 7
Hi ChrisNZ,

It is a character.
andreas_lds
Jade | Level 19

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.

FreelanceReinh
Jade | Level 19

@NJGIRL wrote:

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);

...

Hi @NJGIRL,

 

Add type to the KEEP= list.

 

Also add the missing quotation mark in


label = 'ERROR ;

 

Tom
Super User Tom
Super User

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;

 

NJGIRL
Obsidian | Level 7
THANKS SO MUCH TOM. YOU ARE VERY GOOD AT QUICKLY REVIEWING CODE AND SEEING THE OBVIOUS:()

(I guess the answer to your questions would be this: I was staring at it for way too long and couldn't see beyond the weeds. got way too wrapped up it. This happens to me when I stare at code for hours and hours every day!! PHEW.:) 🙂

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 1271 views
  • 2 likes
  • 5 in conversation