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

I'm fairly new to SAS but not z/OS and other languages on that platform.

 

I'm reading a dataset that has data stored in as a hex value.  In my example, the value stored in one byte is x'76'.  I need to convert this to the decimal equivalent of 118 and then add 1900 (it's a year).  I've searched many samples and found PUT or INPUT statements that seem like they should work but none have so far.  If someone can provide a sample statement to do this, I'd greatly appreciate it. 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Since you are use mainframe I will assume that by "dataset" you actually mean that you have a raw file that you want to read into a SAS dataset.  To read binary data use the PIB informat.

Let's make a sample file.

filename test temp;
data _null_;
  file test recfm=f lrecl=10;
  put 'ABCDEFGHI' '76'x ;
run;

And then read it.

data want ;
  infile test recfm=f lrecl=10;
  input name $9. yr pib1.;
  list;
  yr=yr + 1900;
  put name= yr= ;
run;
46    data want ;
47      infile test recfm=f lrecl=10;
48      input name $9. yr pib1.;
49      list;
50      yr=yr + 1900;
51      put name= yr= ;
52    run;

NOTE: The infile TEST is:

      Filename=...
      RECFM=F,LRECL=10,File Size (bytes)=10,
      Last Modified=31Aug2018:11:37:12,
      Create Time=31Aug2018:11:37:12

name=ABCDEFGHI yr=2018
RULE:     ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+--
1         ABCDEFGHIv
NOTE: 1 record was read from the infile TEST.
NOTE: The data set WORK.WANT has 1 observations and 2 variables.

 

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

Since you are use mainframe I will assume that by "dataset" you actually mean that you have a raw file that you want to read into a SAS dataset.  To read binary data use the PIB informat.

Let's make a sample file.

filename test temp;
data _null_;
  file test recfm=f lrecl=10;
  put 'ABCDEFGHI' '76'x ;
run;

And then read it.

data want ;
  infile test recfm=f lrecl=10;
  input name $9. yr pib1.;
  list;
  yr=yr + 1900;
  put name= yr= ;
run;
46    data want ;
47      infile test recfm=f lrecl=10;
48      input name $9. yr pib1.;
49      list;
50      yr=yr + 1900;
51      put name= yr= ;
52    run;

NOTE: The infile TEST is:

      Filename=...
      RECFM=F,LRECL=10,File Size (bytes)=10,
      Last Modified=31Aug2018:11:37:12,
      Create Time=31Aug2018:11:37:12

name=ABCDEFGHI yr=2018
RULE:     ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+--
1         ABCDEFGHIv
NOTE: 1 record was read from the infile TEST.
NOTE: The data set WORK.WANT has 1 observations and 2 variables.

 

zossysprog
Calcite | Level 5

Thank you.  This is exactly what I needed. 

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
  • 2 replies
  • 986 views
  • 0 likes
  • 2 in conversation