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.
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.
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.
Thank you. This is exactly what I needed.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.