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

Hi,

I am trying to read some non-readable values from a dataset and write it as numeric field. But I am not getting the exact output.

Field legth in inputfile is 5 bytes. and non-readable format.In output, I need to write the same as follows:

Output:

Field length should be 13 bytes with two decimal points and with leading spaces:

'          01.50'

'          13.62'

'        100.21'

'          81.1'

Please help me. I am new to SAS and handling packed decimal values for first time.

Thank you.

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Why would you NOT want the zero before the decimal place?

SAS does not really support that format directly, but you could perhaps build your own.

proc format ;

  picture nozero

  low- -1='000000000.99' (prefix='-')

  -1-<0 = '99' (prefix='         -.' multiplier=100)

  0-1 = '99' (prefix='          .' multiplier=100)

  1-high='0000000000.99'

;

run;

data _null_;

  input x @@;

  put x 13.2 +1  x nozero.;

cards;

-1 1.3 0.34 0.25 -.24 1.24 0

;;;;

        -1.00         -1.00

         1.30          1.30

         0.34           .34

         0.25           .25

        -0.24          -.24

         1.24          1.24

         0.00           .00

View solution in original post

9 REPLIES 9
Reeza
Super User

What are you trying to read from (CSV, TXT, DB) and how did you read it, what was your code?

Santhoshcsc
Calcite | Level 5

I am trying to read from a flat file in mainframes. Fields are in fixed positions.

Input File:

Data ifile;

@01 Name $8.

@09 Age 02.

@11 Appthrs pd 5.;

datalines;

Johhny 25 $@%%^

David  54 *&$#@

Output:

date ofile:

set ifile;

format appthrs pd5;

Put

@01 Name $8.

@09 Age 02.

@11 Appthrs 13.2.;

Expected output:

Johhny 25 12.21

David  54 05.50

ballardw
Super User

Your last value does not display two decimals.

Also what is your target destination. I would assume text but ...

And should the output be actually quoted or was that just to show the leading spaces?

If writing to text then an F13.2 format should work unless you actually need the quotes.

If the input looked like 10021 and needs to be read as 100.21 then an input format of F5.2 would work. Put to assign an input format you'll need to use a data step.

Tom
Super User Tom
Super User

If you really have PD data with two decimal points then you should use a program like this:

data have ;

  infile 'source data file' ;

  file 'new source data file' ;

  input name $8. age 2. appthrs S370FPD5.2;

  put name $8. age 2. appthrs 13.2 ;

run;


If you data really has values like you presented then the PD format for those values would look like these HEX codes.

x=1.5    y=000000150C

x=13.62  y=000001362C

x=100.21 y=000010021C

x=81.1   y=000008110C

Santhoshcsc
Calcite | Level 5

Hi Tom,

Thank you.

Its working fine. But, if value is .25 in input dataset, then I am getting output with leading zero i.e 0.25. How to remove the zero from that field in output?

Tom
Super User Tom
Super User

Why would you NOT want the zero before the decimal place?

SAS does not really support that format directly, but you could perhaps build your own.

proc format ;

  picture nozero

  low- -1='000000000.99' (prefix='-')

  -1-<0 = '99' (prefix='         -.' multiplier=100)

  0-1 = '99' (prefix='          .' multiplier=100)

  1-high='0000000000.99'

;

run;

data _null_;

  input x @@;

  put x 13.2 +1  x nozero.;

cards;

-1 1.3 0.34 0.25 -.24 1.24 0

;;;;

        -1.00         -1.00

         1.30          1.30

         0.34           .34

         0.25           .25

        -0.24          -.24

         1.24          1.24

         0.00           .00

Santhoshcsc
Calcite | Level 5

Thank you so much.. It worked well.

ballardw
Super User

Also is this IMPLIED decimals, which is just showing the number without a decimal point and is assumed to be in a certain location or actual packed decimal which is a specific form of encoding data in binary values.

SAS Innovate 2025: Call for Content

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 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 9 replies
  • 5024 views
  • 2 likes
  • 5 in conversation