08-06-2016 12:16 AM
I'm tyring to conver month number (e.g. 1,2,3) to name (e.g. JAN, FEB, MAR) in a field "Month" which is character field.
I tried below code;
INVALUE Month '1'='JAN', '2'='FEB','3'='MAR',
But it got errored out and error says that 'JAN' was not acceptable format. I'm not sure what that means....
Does anyone how to fix this or know a batter to do?
08-06-2016 01:11 AM
Thank you for your reply.
I tried below and it returned as 'AUG' only. I guess that's today's month....
Can you let me know where I can specify the dataset and field name?
08-06-2016 01:15 AM
The format is MONNAME. Apply it the same way you were planning to use your custom format. It will only work of you have a full SAS date, numeric with a date format not a character or number 1/2/3.
08-06-2016 01:57 AM
Thank you for your reply. I understand that I should have SAS date field to use the MONNAME function, but still couldn't get what I need.
Let me clarify what I'm doing again.
In a data set "test", I have a date filed "purchase_date" which has date in MM/DD/YYYY format. I wanted to add new field "purchase_month" in month name format (JAN, FEB etc) based on "purchase_date".
Right now, I did not know MONNAME function, thus I pulled month as numeric from "purchase_date" and tried to conver it to name. But it sounds I should be able to pull month name (JAN, FEB) from "purchase_date".
Can you please let me know once again how I can do that with MONNAME function?
08-06-2016 02:06 AM - edited 08-06-2016 02:07 AM
Since you want a new variable, create a new variable identical to the date and apply format.
Month = purchase_date;
format month MONNAME.;
purchase_date as month format=MONNAME.
Or convert to character month.
08-06-2016 02:26 AM
I think I'm getting, but it's not quit working yet.
I tried your 1st code as
format purchse_month MONNAME3.;
Then, I have . in the 1st cell and everything god shifted down by 1 row.
Do you know why it got shifted?
08-06-2016 02:44 AM
Thank you very much for your help!!!!
And thank you for teaching me all other codes, as well. I haven't tested all those yet, but will test them later to learn new codes.
08-06-2016 12:49 AM - edited 08-06-2016 12:50 AM
There's no commas between the list of values. I also wouldn't recommend using the name month as its a function.
If you convert it to a SAS date you can use MONNAME format.
Proc format; InValue $ monthFmt '1' = 'Jan' '2' = 'Feb' ... ;
Perhaps if you explain how you plan to use it we can suggest more efficient methods.
08-06-2016 01:09 AM
Thank you for your reply.
It did not work.
Where do you specify the dataset name?
I changed the field to "purchase_month", and had below.
InValue $ purchase_monthFmt
'1' = 'JAN'
'2' = 'FEB'
'3' = 'MAR';
Did i have anything incorrect?
08-06-2016 01:58 AM
You are using Invalue keyword that will create informat.
What I understand with your question that you want to convert 1 to Jan which can be done using format. Be sure what do you want Format or Informat.
Another point is you are considering 1 as character in your code. Ensure that your input varaible where you are applying format is charcter type
Proc Format; Value $ purchase_monthFmt '1' = 'JAN' '2' = 'FEB' '3' = 'MAR'; Run;
08-06-2016 02:12 AM
It seems it ran but nothing returned.
In Log Summary, it says Format $PURCHASE_MONTH has been output.
But I would like to overwite it in the same dataset in purchase_month filed where I have 1,2,3 etc.
Is there other code I need to have?
Need further help from the community? Please ask a new question.