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 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 1011 views
  • 3 likes
  • 2 in conversation