I'm reading in zoned decimal # with a decimal point, ZD, and converting to S370FZDS. When i PUTLOG the S370FZDS var, the decimal point is missing in the log. How do i get the decimal point to display?
Example I have an input # as: 0120{ I would like the output to be +01.200
DATA _NULL_;
INPUT X ZD5.3;
Y=PUT(X,S370FZDS7.3);
PUTLOG X= Y=;
DATALINES;
0025{
0025}
1234A
;
RUN;
output: X=0.25 Y=+000250 X=-0.25 Y=-000250 X=12.341 Y=+012341 The decimal point is missing from y variable
Not sure if this what is needed but possibly a picture format can suffice:
Proc format library=work; picture sign low -<0 = '0000000009.000' (prefix='-') 0 = '0' (noedit) 0<- high= '0000000009.000' (prefix='+') ; run; data work.test; x = '1234A'; output; x = '5432M'; output; x = '0032M'; output; x = '00000'; output; run; data work.result; set work.test; y = input(x, zd5.3); format y sign.; run;
The format you have used to display Y isn't correct.
Use s370fzds7.3 as informat, that is equivalent to the informat ZD5.3 you have used, probably in MF.
In order to get right result use format 5.3 or comma5.3:
y = put(x, 5.3);
/*or*/ y = put(x, comma5.3);
/*or*/ put y 5.3; /* show in log */
i get the decimal point now based on using "Y=PUT(X,7.3);" But, the leading sign is gone from the positive #'s.
DATA _NULL_;
INPUT X ZD5.3;
Y=PUT(X,7.3);
PUTLOG X= Y=;
DATALINES;
0025{
0025}
1234A
;
RUN;
log:
X=0.25 Y=0.250
X=-0.25 Y=-0.250
X=12.341 Y=12.341
Example input: 1234A should be output as: +12.341
The default value is positive unless it is negative.
Why do you need the + sign ?
Anyway you can check the sign using function SIGN
s = sign(<numeric_variable>);
/* s=1 for positive, -1 for negative, 0 for zero */
ok, thx.
The recipient of the file would like to see both positive & negative signs in front of every number. They would like an explicit indication of
a number's sign.
The reason i had chosen, S370FZDS is because the documentation says, "Leading sign of – (hexadecimal 60) or + (hexadecimal 4E)". Is there something here i'm not understanding?
I had thought this would be the format to use to get leading signs in the output along with any required decimal point.
In my example, i was hoping that an input value of 1234A would be output as +12.341 by using format S370FZDS
What SAS platform are using?
I worked long time ago on MF. Now I'm using SAS University Edition with windows.
I cant find any format to force the + sign for positive values.
The only way I know is:
proc format lib=work;
value sgn
-1 = '-'
0 = ' '
1 = '+
; run;
data test;
x = 1234A; output;
x = 5432M; output;
x = 0; output;
run;
data result;
set test;
y = input(x, zd5.3);
s = sign(y);
if s=1 then want = cat(put(s,sgn.), put(y,7.3));
else want = put(y,7.3);
run;
Not sure if this what is needed but possibly a picture format can suffice:
Proc format library=work; picture sign low -<0 = '0000000009.000' (prefix='-') 0 = '0' (noedit) 0<- high= '0000000009.000' (prefix='+') ; run; data work.test; x = '1234A'; output; x = '5432M'; output; x = '0032M'; output; x = '00000'; output; run; data work.result; set work.test; y = input(x, zd5.3); format y sign.; run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: