Find smallest difference between dates SAS - date

I have this HW question that is asking me:
Write a SAS Program to creates a data set that contains test date closest to
delivery date. Your program must work for any test date and delivery date.
Here is what I have done so far. The data sources are in seprate sheets in excel which I p pulled in and merged and there is only 1 deliver date and 21 test dates. I figure the best way to find the closest day was the absolute value of the smallest difference, then use proc sort because that is the only proc command we are allowed to use other than proc import and export. Any ideas/help/whatever would be appreciated thanks.
proc import datafile = "C:\Users\file1.xls"
dbms=xls replace out=labs; sheet = "labs";;
run;
proc import datafile = "C:\Users\file1.xls"
dbms=xls replace out=delivery; sheet = "delivery";
run;
data dl;
merge delivery labs;
dd = delivery_date;
diff = dd - Test_date;
run;
Here is the data they are both in 1 column didn't know how to format that here.
Sheet 1:
delivery_date
11/16/2011
Sheet 2:
Test_date
13-Mar-11
10-Apr-11
20-May-11
9-Jun-11
31-Jul-11
17-Aug-11
12-Sep-11
10-Nov-11
11-Oct-11
12-Dec-11
29-Feb-12
13-Mar-13
10-Apr-10
20-May-10
9-Jun-10
21-Jul-11
15-Aug-11
15-Sep-11
19-Oct-11
21-Nov-11
22-Dec-11

It sounds like you are on the right track. Given that this is homework, I'm not going to give you a complete solution, but here are some components you may find helpful:
First, you should look at the SAS website for more information about the absolute function (since that is the route you want to take):
SAS/IML(R) 9.3 User's Guide: ABS Function
Next, you may want to review the documentation for PROC SORT. It will be useful for finding the smallest difference.
For getting only one record, you may find the OBS Data Set Option helpful.
(Hint: you may need to create a second dataset.)

Related

Google Sheets - DATE format not working on imported Date in TEXT format

I text based .csv file with a semicolon separated data set which contains date values that look like this
22.07.2020
22.07.2020
17.07.2020
09.07.2020
30.06.2020
When I go to Format>number> I see the Google sheets has automatic set.
In this state I cannot use and formulas with this data.
I go to Format>number> and set this to date but formulas still do not see the actual date value and continue to display an error
Can someone share how I can quickly activate the values of this array so formulas will work against them?
I would be super thankful
Where the date are in column A, starting in cell A1, this formula will convert to DATE as a number, after which you apply formatting to Short Date style.
=ARRAYFORMULA(IF(A1:A="",,DATE(RIGHT(A1:A,4),MID(A1:A,4,2),LEFT(A1:A,2))))
Hopefully(!) the dates stay as text, otherwise Google Sheets would sometimes detect MM/dd/yyyy instead of dd/MM/yyyy, and you won't be able to distinguish between July 9th and September 7th in your example.
Solution #1
If your locale is for instance FR, you can then apply
=arrayformula(if(A1:A="";;value(A1:A)))
solution#2
you can try/adapt
function importCsvFromIdv1() {
var id = 'the id of the csv file';
var csv = DriveApp.getFileById(id).getBlob().getDataAsString();
var csvData = Utilities.parseCsv(csv);
csvData.forEach(function(row){
date = row[0]
row[0] = date.substring(6,10)+'-'+date.substring(3,5)+'-'+date.substring(0,2)
})
var f = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
f.getRange(1, 1, csvData.length, csvData[0].length).setValues(csvData);
}
First thanks to those that suggested a fix. I am not really a programmer and get cold sweats when I see suggesting of running scripts to solve simple problems. Sorry guys.
So the (non programmer) solution with the dates was to do a find/replace (CTRL + H) and replace all the (.)dots with (/)slashes, then to make sure the column is formatted as a date, then Google finally understands it as a date.
With the accounting values as well, I had to do the same find/replace to remove all the ' between thousands, then google woke up and understood them as numbers.
I am significantly underwhelmed by this from Google. They are getting too fat and lazy. They need some competition.

Tableau: "Unknown function DATEPARSE called" after data source migration

Small question regarding Tableau and the DATEPARSE function please.
I used to have a CSV, nothing special, that has a column Mytimestamp.
The values of the column Mytimestamp would be just like those: Mytimestamp 1628670242328 1619671382146
DATE(DATEPARSE ( "yyyy-MM-dd HH:mm:ss", STR(DATEADD('second', (INT([Mytimestamp]/1000)), #1970-01-01#)) ))
Again, this worked really great, no problem.
Now, we have couple of other data sources, and I just replaced the original data source, the CSV file, to those new datasource.
Unfortunately, all dashboard using this broke, with this issue.
"Unknown function DATEPARSE called".
May I ask how to fix this, and get the behavior I was having with the CSV please?
What would be an alternative to this DATEPARSE function which can help "convert" those timestamps into a human readable format.
Thank you
The correct answer is to use DATETIME
DATE(DATEPARSE ( STR(DATEADD('second', (INT([Mytimestamp]/1000)), #1970-01-01#)) ))
Some data sources, such as CSV, supports DATEPARSE
But some others does not, and the DATETIME is the answer.

Export Calendar Date to spreadsheetout - Time Stripped off - Google Script

I am using Google Script to export some calendar events to a spreadsheet; the relevant portion of my script is below:
var details=[[mycal,events[i].getTitle(), events[i].getDescription(), events[i].getLocation(), events[i].getStartTime(), myformula_placeholder, ('')]];
var range=sheet.getRange(row,1,1,7);
range.setValues(details);
This code works but the "time" that is put into the spreadsheet is a real number of the form nnnnn.nn. On the spreadsheet itself the date looks great using the integer to the left of the decimal (eg 10/15/2017) but the decimals are part of the value and therefore are part of the spreadsheet value.
My script drops the data into a sheet in my workbook, and another sheet reads the rows of data with the above date types, looking for specific date info from the other sheet using the match function (for today()). That would work fine if I could get rid of the decimals.
How can I use what I have above (if I stray far from what I have found works I will be redoing hours of work) but adding just what is needed to only put into the output spreadsheet the whole number portion so I have a pure date that will be found nicely by my match function using today()?
I have been digging, but errors abound in trying to put it all together. "Parse" looked like a good hope, but it failed as the validation did not like parse used within getStartTime. Maybe I used it in the wrong manner.
Help would be appreciated greatly.
According to the CalendarApp documentation, getStartTime() generates a Date object. You should be able to extract the date and time separately from the date object:
var eventStart = events[i].getStartTime(); // Returns date object
var startDate = eventStart.toDateString(); // Returns date portion as a string
var startTime = eventStart.toTimeString(); // Returns time portion as a string
You could then write one or both of these to your spreadsheet. See the w3schools Javascript Date Reference for more information:
http://www.w3schools.com/jsref/jsref_obj_date.asp
If you If you want to specify the string format, you can try formatDate in the Utilities service:
https://developers.google.com/apps-script/reference/utilities/utilities#formatdatedate-timezone-format
You could just use the Math.floor() function
http://www.w3schools.com/jsref/jsref_floor.asp
which will round the real number to an integer. Your line would then read:
var details=[[mycal,events[i].getTitle(), events[i].getDescription(), events[i].getLocation(), Math.floor(events[i].getStartTime()), myformula_placeholder, ('')]];

How to change a cell's code after it's been moved in Excel using VBA

I have an Excel VBA Script I've written with help, I am not a neophyte when it comes to coding, but to me so far Excel VBA has been an arsenic nightmare wrapped in a sugar pill sold by MS as a language easy to learn.
Ok, rant out of the way sorry, but I digress.
Here is the complete script:
Option Explicit
Sub tgr()
Dim wsB As Worksheet 'BackOrder
Dim wsJ As Worksheet 'Jobs List
Dim wsA As Worksheet 'Archive
Dim LastRow As Long
Set wsB = Sheets("BackOrder")
Set wsJ = Sheets("Jobs List")
Set wsA = Sheets("Archive")
With Application
.ScreenUpdating = False
.DisplayAlerts = False
.EnableEvents = False
.Calculation = xlCalculationManual
End With
With Intersect(wsJ.UsedRange, wsJ.Columns("N"))
.AutoFilter 1, "<>Same"
With Intersect(.Offset(2).EntireRow, .Parent.Range("B:L"))
.Copy wsA.Cells(Rows.Count, "B").End(xlUp).Offset(1)
.EntireRow.Delete
End With
.AutoFilter
End With
LastRow = wsB.Range("B6").End(xlDown).Row
wsB.Range("P5:Q5").Copy wsB.Range("P6:Q" & LastRow)
Calculate
wsB.UsedRange.Copy Sheets.Add.Range("A1")
With Intersect(ActiveSheet.UsedRange, ActiveSheet.Columns("Q"))
.AutoFilter 1, "<>Different"
.EntireRow.Delete
With .Parent
.AutoFilterMode = False
Intersect(.UsedRange, .Columns("G")).Cut .Range("F1")
Intersect(.UsedRange, .Columns("H")).Cut .Range("G1")
Intersect(.UsedRange, .Columns("L")).Cut .Range("H1")
Intersect(.UsedRange, .Columns("N")).Cut .Range("I1")
Intersect(.UsedRange, .Range("B:J")).Copy wsJ.Cells(Rows.Count, "B").End(xlUp).Offset(1)
.Delete
End With
End With
LastRow = wsJ.Cells(Rows.Count, "B").End(xlUp).Row
wsJ.Range("M1:T1").Copy
wsJ.Range("B3:I" & LastRow).PasteSpecial xlPasteFormats
wsJ.Range("U1:W1").Copy wsJ.Range("J3:L" & LastRow)
wsJ.Range("X1:Y1").Copy wsJ.Range("M3:N" & LastRow)
With Application
.Calculation = xlCalculationAutomatic
.EnableEvents = True
.DisplayAlerts = True
.ScreenUpdating = True
End With
End Sub
As you can see this is a three page script, BackOrder, Jobs List, and Archive, what I need to do is in Archive. The cells in Columns in J & K use TODAY() as a way to tell the rest of the script when it looks in the cell in column F how many days early or late it is.
Column J shows early, Column K shows late.
Column J's script is:
=IF(F3-TODAY()<0,"",F3-TODAY())
Column K's script is:
=IF(TODAY()-F3<1,"",TODAY()-F3)
Column F in this case is part of the larger script, which moves data via an import and has no formatting.
Now, when I bring row into Archive, I want it to be where the cells, instead of having TODAY() in either script, I want it to show the date it was moved over there, so it will still be today, but instead of TODAY(), it will have the date in this format ##/##/##. It will "freeze" the count of J & K so it will be accurate from that day forward, so we will know if it was shipped late, early, or on time.
Is this possible, and if so how?
You are confusing worksheet functions and VBA functions. You stopped your rant too soon although I think Word VBA is the worst version.
With the user interface, I can go to cell A1 and type "4apr12". Excel recognises this as a date, stores the value as 41003 and sets the format to "dd-mmm-yy" which is the standard format closest to what I typed.
Alternately, I could type "41003" then go to the format menu and select or enter a date format of my choice.
Yet another choice is to type "=TODAY()". Excel stores the value as "=TODAY()" but because of the leading equals, it evaluates this as an expression when it is entered and displays the value as a standard date (format dd/mm/yy here in the UK) and re-evaluates the expression when the workbook is opened and saved and when told to do so via the Calculate options.
VBA functions are different. Even when they do the same thing, they often have different names. The nearest equivalent to TODAY() is Now(). This function returns the current date and time as a number. The integer part is the days since 1-Jan-1900; the fraction part is (Number of seconds since midnight)/(Number of seconds in a day). So at midday today, Now() would have returned "41003.5". This is a number; I can multiple it by two, subtract 5000 or whatever.
With VBA, I could execute:
Range("A1").Value = "4apr12"
Excel recognises this as a date just as if I had typed it from the user interface.
Alternatively, I could execute:
Range("A1").Value = 41003.5
This is just a number and will be stored and displayed as 41003.5.
If I want it to be displayed as a date, I must execute:
With Range("A1")
.Value = 41003.5
.NumberFormat = "dd mmm yy"
End With
The value is still saved as 41003.5 but I have told Excel to display it as 4 Apr 12.
I can execute:
Range("A1").Value = "=TODAY()"
This is treated just as if I had typed this formula from the interface.
But suppose I execute:
With Range("A1")
.Value = Now()
.NumberFormat = "dd mmm yy"
End With
Now() returns the current date and time as a number. Excel stores it as a number but displays it as a date because I have told it to. It will never re-evaluate because it is a simple numeric value not an expression involving functions.
I hope you this makes sense and helps you get your mind around the differences between Worksheet functions and VBA functions. Excel and VBA are like learning to drive a car. The first time you KNOW you will NEVER be able to do all these different things at the same time. Yet, a month or two later, you are playing with the pedals, the gear stick, wheel and indicator while checking the mirror. I do not understand why people think patting your head and rubbing your stomach is such as big deal. All I can say is that sudenly the mist will clear and Excel and VBA will make sense.

Looking for Function or tips to extract Image Access Date and time in matlab

I have an array of images in an folder,and i would like to read them in the order they copied in the folder i.e. for example there are three images if 1st image copied at 7.15 PM second at 7.45PM and third 7.55PM, i would like to read image which copied first in my folder in terms of time and date.? so how to sort image in that order? have any idea.
On the other hand,if right click on any image,and go to proporties,you will find three types of date i.e. Created date and time, modified date and time and access date and time. i would like to extract the access date and time of any image in matlab? how to do that? pls guide.
I am not sure if there is a way to find the atime with a MATLAB function, you might have to do a system call. On most unix-like systems it would look something like this.
>> [status result] = system('ls -trlu')
I don't know if it's possible to get the "access" date, but you can get the "modified" date with the dir function. By doing:
d = dir('directory');
time = d.date;
You then need to extract the relevant information from the string output of d.date and sort it accordingly.