BookmarkSubscribeRSS Feed
sp41832
Calcite | Level 5

I have a dataset which contains Date as  20-11-2017 format, time  as 00:12:58 and status variable of length 35.

I want to retain the same data format as above and for Time i need 12 hr format , for status variable i took statu $ but it gives only first 8 character since the default is 8 however i need full length.

 

Kindly Advice.

6 REPLIES 6
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Post test data in the form of a datastep, follow this post if you need to:

https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat...

 

Then show what you want the output to look like.  Your post doesn't make sense as it is.

sp41832
Calcite | Level 5

Request id,Date,Request time,Dropoff time,Pickup point,Driver id,Status
1,11-07-2016,00:11:31,12:43:12 AM,Airport,285,Trip Completed
2,11-07-2016,00:12:58,NA,Airport,NA,No Cars Available

 

 

My Data looks as above.

art297
Opal | Level 21

Does the following do what you want?:

 

data have;
  informat date date9.;
  informat time time8.;
  informat status $35.;
  input date time status &;
  cards;
20nov2017 00:12:58 this is the time for all good men
;

data want;
  format date ddmmyyd10.;
  format time timeampm12.;
  format status $35.;
  set have;
run;

Art, CEO, AnalystFinder.com

 

Shmuel
Garnet | Level 18

What kind of input dataset you have ? Is it a sas dataset or a flat file like .csv or .txt ?

 

You said that:  status variable of length 35 ... but it gives only first 8 characters 

That makes me think it is a flat file. I guess next code may help you:

 

data have;
     infile datalines truncover ;
     input date ddmmyy10. @+1 time time8. @+1 status $35. ;
    format date ddmmyy10. time time8.;
datalines;
20-11-2017 00:12:58 status is given as free text
25-12-2017 01:15:00 status is a dummy line
;
run;

The result, 1st line will be like:

20/11/2017  0:12:58 status is given as free text

 

the date with / instead - and time without leading zero

 

art297
Opal | Level 21

You could take care of all of your NA instances, and desired formatting, with something like:

 

proc format;
  invalue dmissing
  'NA'=.
  other=[anydtdtm.]
  ;
  invalue nmissing
  'NA'=.
  other=[8.]
  ;
run;

data want;
  informat date ddmmyy10.;
  informat Request_time Dropoff_time dmissing.;
  informat status $35.;
  informat Driver_ID nmissing.;
  format date ddmmyyd10.;
  format Request_time Dropoff_time timeampm12.;
  format status $35.;
  infile cards dlm=',';
  input Request_id Date Request_time Dropoff_time Pickup_point $ Driver_id Status &;
  cards;
1,11-07-2016,00:11:31,12:43:12 AM,Airport,285,Trip Completed
2,11-07-2016,00:12:58,NA,Airport,NA,No Cars Available
;

Art, CEO, AnalystFinder.com

sp41832
Calcite | Level 5

It is CSV file having data as below

 

Request id,Date,Request time,Dropoff time,Pickup point,Driver id,Status
1,11-07-2016,00:11:31,12:43:12 AM,Airport,285,Trip Completed
2,11-07-2016,00:12:58,NA,Airport,NA,No Cars Available
3,11-07-2016,00:12:58,1:19:12 AM,Airport,80,Trip Completed

 

I want to read the whole data as is also i need only fields Request id,Date,Request time and Status , and i wrote the belo code.

 

data uber;
infile '/folders/myfolders/datafiles/uber.csv' delimiter= ',' firstobs=2;

input request_id Date DDMMYY10. status $35;
run;

 

 

 

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 969 views
  • 0 likes
  • 4 in conversation