BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Haydn
Quartz | Level 8

hello,

 

I have two datasets that I'm using in SAS VA and also in excel and powerbi. My boss wants reports in all 3 products.

 

Dataset 1 has  variable called "StartDate" and this is in DATETIME18. format. (From an external organistaion) 

Dataset 2 has a variable called "Date" and this is DATE9. format. (From a SharePoint List)

These two variables have entries for every day of the week. 

 

I merge these two dataset, however I'd like to create a common variable  from the above and convert these to mmm yyyy (not just format). Is there a way to do this>

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisNZ
Tourmaline | Level 20

This works:

DATESTR = put(DATETIME,dtmonyy.);

Just make it a habit to browse the list of formats to find what you need.

 

View solution in original post

7 REPLIES 7
ChrisNZ
Tourmaline | Level 20

> convert these to mmm yyyy (not just format)

You mean you want a string as output?

Why not a date that you can format as you will?

 

> These two variables have entries for every day of the week. 

How will you keep the weekly detail if you just keep monyy?

Haydn
Quartz | Level 8
How will you keep the weekly detail if you just keep monyy? (I'll still have the original variables to report at that level)
Why not a date that you can format as you will? (I'm finding that different products treat the formats differently) As an example I used the following. ReportingMonth= input(symget(StartDate),date9.);
format ReportingMonth monyy7.;
This works fine in SAS EG, but when used in PowerBI, it converts it back to dd/mm/yyy.
ChrisNZ
Tourmaline | Level 20

This works:

DATESTR = put(DATETIME,dtmonyy.);

Just make it a habit to browse the list of formats to find what you need.

 

SASKiwi
PROC Star

How are you getting your SAS dataset into PowerBI then? For reporting to work correctly in all products your date variables will have to be defined as 'proper dates', not dates stored as text strings. For Excel that means a numeric containing the number of days from 1 Jan 1900, for SAS the number of days from 1 Jan 1960 and for PowerBI it will need to be a PowerBI date (not sure how these are stored internally).

Kurt_Bremser
Super User

@Haydn wrote:

This works fine in SAS EG, but when used in PowerBI, it converts it back to dd/mm/yyy.

Then apply the proper format in Power BI. Storing dates as strings is, to be polite, not a bright thing to do in any environment.

Haydn
Quartz | Level 8
To be clear, I DO NOT want to store these as strings.
I wanted to create variable that where 01/07/2020 is for the Date variable, another variable is created, called ReportingMonth and this has the value of July2020, as date. I am aware I can then format as these in other products like SAS VA, Excel etc. But I was hoping avoid any sort of additional work on (such as formating etc) in other products. Especially given I have to create the same report in 3 different products. While not time consuming for one report, it does add up over time. But I guess this is not possible.
Tom
Super User Tom
Super User

Do you want get a single date value for every possible day within the same month?

month=intnx('month',date,0);
format month monyy7.;

If you prefer it as a string you can skip the extra variable and just store the formatted value as the formatted value is the same no matter what day of the moth the DATE value actually has.

month=put(date,monyy7.);

If you have some values that start as datetime then you will need to convert those to dates for the first method:

month=intnx('month',datepart(datetime),0);

Or use a datetime format for the second method.

month=put(datetime,dtmonyy7.);

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Discussion stats
  • 7 replies
  • 5116 views
  • 2 likes
  • 5 in conversation