SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sasDante
Calcite | Level 5

 

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
1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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;

View solution in original post

6 REPLIES 6
Shmuel
Garnet | Level 18

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 */
sasDante
Calcite | Level 5

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

Shmuel
Garnet | Level 18

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 */
sasDante
Calcite | Level 5

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

 

Shmuel
Garnet | Level 18

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;
ballardw
Super User

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;

sas-innovate-white.png

Join us for our biggest event of the year!

Four days of inspiring keynotes, product reveals, hands-on learning opportunities, deep-dive demos, and peer-led breakouts. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1408 views
  • 0 likes
  • 3 in conversation