BookmarkSubscribeRSS Feed
NonSleeper
Quartz | Level 8

So my data comes from an online survey and consists of, among others, two variables: ID and Time of submission. The later is a string variable and looks like this:

2 February 2015 7:18 PM

The question arises from the fact that some participants submitted their responses more than once. So I want to select the most recent submission and drop others. Can you suggest a macro-free program that can do that work? I've got stuck in figuring out a numeric measurement reflecting time of submission from the original variable or something like that which will help with sorting.

Any thoughts are appreciated.

3 REPLIES 3
Tom
Super User Tom
Super User

Note sure how a macro could help with this type of problem.

Just convert the text variable to a numeric variable.  Then you can sort and take the last one.

dt = input(time_of_submission,anydtdtm.);

format dt datetime19.;

NonSleeper
Quartz | Level 8

It's interesting that when I import the data from excel, SAS automatically converts the submission variable to date format. For example, the value of "26 February 2015 7:19 PM" becomes "26FEB15:19:19:49". I check the format and it's DATETIME16.; I guess the length is the reason the seconds shows up though they aren't in the original variable. I change the format to DATETIME14. and things look pretty good now.

Tom
Super User Tom
Super User

Probably the formatting in Excel is hiding the seconds.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 797 views
  • 3 likes
  • 2 in conversation