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.
Post test data in the form of a datastep, follow this post if you need to:
Then show what you want the output to look like. Your post doesn't make sense as it is.
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.
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
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
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
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;
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.
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.