You question if too vague. While you make it more clear in your follow-up post consider this data step and how it might be used.
hi data _null_ - sorry for the vague question. I have a categorical field month in SAS Visual analytics dataset. I was trying to convert to a numeric field so that I could use mdy function. I see your code but how do I use it in SAS VA 7.1?
Try creating a calculated item. In the operators section look for date. There should be one that says month. That will return the number of the month. Don't forget, if your data is coming in with a time, you will need to use the DatePart operator as well.
You can't show character to numeric format...............
In SAS VA
IF ( 'Month'n In ('Jan') )
IF ( 'Month'n In ('Feb') )
IF ( 'Month'n In ('Mar') )
IF ( 'Month'n In ('Apr') )
IF ( 'Month'n In ('May') )
IF ( 'Month'n In ('Jun') )
IF ( 'Month'n In ('Jul') )
IF ( 'Month'n In ('Aug') )
IF ( 'Month'n In ('Sep') )
IF ( 'Month'n In ('Oct') )
IF ( 'Month'n In ('Nov') )
IF ( 'Month'n In ('Dec') )
ELSE . ) ) ) ) ) ) ) ) ) ) )
You can achieve your requirement by doing above.
Thanks & Regards,
This is not good advice. Firstly the question has been answered quite simply by either data _null_'s code, or SAS_Mike's response for VA specific. Secondly, if you need to multiple if statements like that then use select-when syntax:
when('January') then 1;
Thirdly, even if for some reason you need to use if statements, then the nesting is not necessary, you can use else if, the syntax of which is:
if <condition> then <result>;
else if <condition> then <result>
if month="January" then 1;
else if month="Febuary" then 2;
Finally it would be a good idea to look up good coding practice, e.g: lower casing code - other than SQL it just makes it hard to read. Consistent indetation. Align brackets so the set of statements can be clearly identified.
I agree with you. but he wants to calculate in SAS VA. data_null_'s answer is about back end (SAS EG) data calculation and Mike's Answer is suitable when the columns are in date format.
In front end (SAS VA) we are not able to change Character to Numeric (we are able to change Date format to numeric format), in this case we have only one alternative i.e.., if else statement to achieve his requirement.
Thanks & Regards,
I initially tried the nested if function. I am surprised you got it to work. I guess I had to have more patience in order for the nesting conditions to work. Only the first if then condition would work for me. I experimented quite a bit for the conversion of months from Jan - Jul to number series 1 - 6.
Thanks - I was looking for somehting like this. I actually did a very crude conversion in SAS VA. There is a facility to name a new custom category and then use a choice of labels. So what I did was add 6 labels 1-6 and then assign the months Jan - Jul for that. I have to see if that will create further unexpected issues in which case I will try your formula. After creating this custom category, I created another calculated item which took this custom category as input for mdy function. For the year argument, I used 2015. For the date, I had a field from the sas dataset.
See how to use one filter for multiple data sources by mapping your data from SAS’ Alexandria McCall.
Find more tutorials on the SAS Users YouTube channel.