BookmarkSubscribeRSS Feed
kalyan11
Calcite | Level 5

I have data like 202208 and I need to convert it to AUG22. Please help.

 

Thank You.

7 REPLIES 7
kalyan11
Calcite | Level 5
I need to convert 202208 to AUG22 on mainframe. I have an input with the data 202208, 202209 etc. I need to convert them to AUG22, SEP22 on mainframe.
kalyan11
Calcite | Level 5
I would like to know which informat and format need to use to convert that 202208 to AUG22
Patrick
Opal | Level 21

@kalyan11 wrote:
I would like to know which informat and format need to use to convert that 202208 to AUG22

To really answer your question you need to tell us if your source value is a number, a string or already a SAS date value just with a format attached that displays the value as yyyymm.

You then also need to tell us if the result you want should be a SAS date value with a format attached that displays as monyy or if you need a string stored in a character variable.

 

Have a look into below sample code. If there is anything in it you don't understand then consult the SAS docu - format and informats and even more so how SAS date values work if you don't know that already.

data demo;
  var1_char ='202208';
  var2_num  =202208;

  var1_SAS_dt_val=input(var1_char,yymmn6.);
  var2_SAS_dt_val=input(put(var2_num,f6.),yymmn6.);
  format var1_SAS_dt_val var2_SAS_dt_val monyy6.;

  var1_string=put(var1_SAS_dt_val,monyy6.);
  var2_string=put(var2_SAS_dt_val,monyy6.);

run;

proc print data=demo;
run;

Patrick_0-1706794506063.png

 

PaigeMiller
Diamond | Level 26

Adding to the fine advice from others: it doesn't matter where the values come from, database or Excel or otherwise. It matters what the values are in your SAS data set. And to make the proper decision about how to program this, as demonstrated above, you MUST know if in SAS these variables are numeric or text (also called "character"), and in many cases, you also MUST know what the format of the SAS variable in the SAS data set is.

 

Although you @kalyan11 have been asked several times to tell us this, you haven't given us this information, and you absolutely will need this to program the conversion properly.

 

You can find this information by running PROC CONTENTS on your SAS data set. Here is an example of running PROC CONTENTS on a different data set:

 

proc contents data=sashelp.cars;
run;

PaigeMiller_0-1706795071831.png

 

As you can see, there is a variable named Cylinders which is numeric, and variable named DriveTrain which is Character. Variable named INVOICE has a format assigned to it.

--
Paige Miller

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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
  • 7 replies
  • 1017 views
  • 2 likes
  • 4 in conversation