SAS not recognizing date format - string

I have the following character date format:
"3/1990"
"4/1990"
"5/1990"
...
I tried the following code:
data work.temps;
set indata;
newdate = input(strip(Date), MMYYSw.);
rename newdate = date;
run;
I keep on getting the following error meassage: Informat MMYYSW was not found or could not be loaded.

You may have to use a different informat to read in the character dates so that SAS can interpret them as numeric (since dates in SAS are actually numeric values), and then format them as MMYYS..
This was tested and works for me:
DATA temps;
FORMAT newdate MMYYS.;
SET indata;
newdate = INPUT(COMPRESS('01/'||date),DDMMYY10.);
RUN;

Try this with anydtdte:
data have;
input date $10.;
_date=input(compress(date,'""'),anydtdte.);
format _date MMYYs7.;
cards;
"3/1990"
"4/1990"
"5/1990"
;
run;

What you refer is a FORMAT, not INformat.
You'll use format with PUT function, for INPUT, you need informat.
Anyway I didn't find a suitable informat to be used directly, so you'll need to do more stuff:
data work.temps;
infile cards truncover;
input Date $10.;
newdate=MDY( scan(Date,1, '/'), 1, scan(Date,2, '/') );
cards;
3/1990
4/1990
5/1990
;
run;
SCAN takes Nth word from a string, MDY creates DATE from Month, Day and Year.
The code above gives the first day of the month.

Related

Reformatting date values when using them as URL parameters in a PowerQuery API request

I have two dates in my Excel table with the following format: "dd-mm-yyyy". These dates need to be sent as URL query parameters to an API endpoint for getting some data using PowerQuery. However, the API endpoint does not accept dates in that format. Therefore, I need to convert them to the format "mm-dd-yyyy" instead for it to work.
For getting the values from my table, I use the following code:
let GetNamedRange=(NamedRange) =>
let
name = Excel.CurrentWorkbook(){[Name=NamedRange]}[Content],
value = name{0}[Column1]
in
value
in
GetNamedRange
This function, called "GetValue", is then called when inserting URL query parameters in my GET request:
Csv.Document(Web.Contents("my.api/leave/leavecsv", [Query = [periodStart = GetValue("periodStart"), periodEnd = GetValue("periodEnd"), department = GetValue("department")]]),[Delimiter=";", Columns=14, Encoding=1252, QuoteStyle=QuoteStyle.None])
Currently the cells for my dates are in Text format. I tried using Date.FromText(...) to format the dates, but I get an error saying the datetime format is invalid.
https://learn.microsoft.com/en-us/powerquery-m/date-fromtext
How can I propertly format my date values before inserting them as URL query parameters using PowerQuery?
Ensure your dates are real dates and set to type date. then you can use the Date.ToText function:
let
theDate = #date(2022,12,7),
output = Date.ToText(theDate,"MM-dd-yyyy")
in
output
If, for some reason, you must maintain your dates as text strings (I'd like to know why, if that's the case), you can convert them first to a "real" date, and then create the string:
let
theDate = "13-12-2022",
output = Date.ToText(Date.FromText(theDate, "en-150"),"MM-dd-yyyy")
in
output
Make sure you pass in a culture and format. i.e.
Date.FromText([Column1], [Format="dd-MM-yyyy", Culture="en-UK"])

Convert string to date format in azure data factory using set variable

I have string date in set variable "20211222"
And I want to convert it into date like 2021-12-22.
And I have use this function in variable set dynamic content
#formatDateTime('20211222', 'yyyy-MM-dd')
But error occur In function 'formatDateTime', the value provided for date time string '20211222' was not valid. The datetime string must match ISO 8601 format
Is there any other function to convert this string "20211222" into date?
Actually the string '20211222' is already in the unambiguous format of YYYYMMDD and will always be interpreted this way. If you need to use this string input as a date, just do a cast:
SELECT CAST('20211222' AS date); -- 2021-12-22
If you wanted to formerly go from your text input YYYYMMDD to a text output of YYYY-MM-DD, then make a round trip:
SELECT CONVERT(varchar(10), CAST('20211222' AS date), 120);
Function formatDateTime expects "a string that contains the timestamp".
Example:
formatDateTime('03/15/2018 12:00:00', 'yyyy-MM-ddTHH:mm:ss')
You would have to manage to input in a timestamp format. The default format for the timestamp is "o" (yyyy-MM-ddTHH:mm:ss:fffffffK), which complies with ISO 8601 and preserves time zone information.
Please use the below logic:
#concat(substring(pipeline().parameters.Test,0,4 ),'-',substring(pipeline().parameters.Test,4,2),'-',substring(pipeline().parameters.Test,6,2))

Python format incomplete date to YYYYMM

As a start, I am extremely new at Python.
I am receiving an Excel file where the date field is incomplete. The value displays as "190808" (YYMMDD) instead of "2019-08-08".
Part of my automation attempt is to move the file to a different location, where the file is renamed. I want to use the date field to change the file name to the file description and date (e.g. "Sales figures 201908").
The code I have only works if the date format is
str(df['Bank date'][0].strftime("%Y%m"))
I have tried dateparser with the following:
dateparser.parse(df['Bank date'][0].strftime("%Y.%m"))
The error I am receiving is 'numpy.int64' object has no attribute 'strftime'
Any help will do.
Thanks.
I modified it slightly and built my own date-string using slicing.
vOldDate = str(df['Bank date'][0])
vNewDate = '20' + vOldDate[:2] + '.' + vOldDate[2:4]
Numpy is interpreting the date as an integer. To use dateparser, you need to convert that value into a string first, then parse that string, and then format the result:
dateparser.parse(str(df['Bank date'][0])).strftime("%Y.%m")
Since the input format is expected, you should specify it to ensure you get the right date:
>>> dateparser.parse(str(190808), date_formats=['%y%m%d']).strftime("%Y.%m")
'2019.08'

Datetime parse exception in C#

I have tried all the ways, however not sure why the string date is not getting converted to datetime.
string windowsTime = "2/21/2009 10:35:14 PM"
DateTime time = DateTime.ParseExact(windowsTime, "MM/dd/yyyy hh:mm:ss tt", null);
I used, DateTime.Parse, ParseExact, Convert.ToDatetime.
But nothing is working, I am getting "String was not recognized as a valid DateTime.".
can somebody advise what am I doing wrong ?
Since the month has only one digit this is correct M.
You also have to use CultureInfo.InvariantCulture instead of null(means current-culture). Otherwise all / will be replaced with the actual date separator of your current culture( for me de-DE it's .):
DateTime time = DateTime.ParseExact(windowsTime, "M/dd/yyyy hh:mm:ss tt", CultureInfo.InvariantCulture);
Custom date and time format strings: the "/" Custom Format Specifier
as specified in the MSDN
"MM" The month, from 01 through 12. More information: The "MM" Custom
Format Specifier.
Custom Datetime

Converting UTC Date to GMT in Groovy / Java

I am working with SoupUI a i need to adjust a Date/time (UTC) that i get back in a response to a GMT Date/time. The date that i get back in the respone looks as followes:
2012-11-09T00:00:00+01:00
I would like to convert this to
2012-11-08T23:00:00Z
Unfortunatly i lack Java skils and therefore also Groovy skils to be able to do this on my own. i did a lot o searches on date convertions but until now i was still unable to find what i was looking for. i will keep searching. if i do manage to get the solution then i will post it here.
Assuming there isn't a colon in the timezone portion, I believe this should work:
// Your input String (with no colons in the timezone portion)
String original = '2012-11-09T00:00:00+0100'
// The format to read this input String
def inFormat = new java.text.SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ssZ" )
// The format we want to output
def outFormat = new java.text.SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ss'Z'" )
// Set the timezone for the output
outFormat.timeZone = java.util.TimeZone.getTimeZone( 'GMT' )
// Then parse the original String, and format the resultant
// Date back into a new String
String result = outFormat.format( inFormat.parse( original ) )
// Check it's what we wanted
assert result == '2012-11-08T23:00:00Z'
If there is a colon in the TimeZone, you'll need Java 7 for this task (or maybe a date handling framework like JodaTime), and you can change the first two lines to:
// Your input String
String original = '2012-11-09T00:00:00+01:00'
// The format to read this input String (using the X
// placeholder for ISO time difference)
def inFormat = new java.text.SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ssX" )

Resources