I have data like 202208 and I need to convert it to AUG22. Please help.
Thank You.
Numeric or character? If numeric, which format is assigned to the variable?
Define "input". Is this manually typed in by somebody, or stored in a file, or supplied to the SAS program as a JCL parameter?
Maxim 1: Read the Documentation.
Date Informats , see YYMMN
From this page, you can also find the documentation of display formats.
@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;
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;
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.
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.
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.