Hi Team,
I facing one issue regarding the hader date, it contains date and time stamp below i mention the input file,
my Req is to remove ifan symbol in the date, I tried multiple scenarios like compress and substr all the things but no use i am facing the issue kindly give sum solutions for the below problem
input file
------------------------------------------------------------------------------------------
H|2020-01-06T14:01:28.0228380Z|1
-----------------------------------------------------------------------------------------------
and the sas code
data ls285;
infile LSFIPYMT;
Input @1 Hdrrtyp $char1.
@3 Hdndate $10. /* Header date */
@14 Hdntime $15. /* Header time */
@32 hdnqty 8.; /* Records in file */
DATA OUT;
SET LS285;
FILE LSSOUT28;
hdndate = substr(hdate,3,10);
hdndate = compress(hdndate,'-');
put @1 Hdrrtyp $char1.
@3 Hdndate $8. /* Header date */
@14 Hdntime $15. /* Header time */
@32 hdnqty 8.; /* Records in file */
run;
proc print data = out;
run;
----------------------------------------------------------------------------------------------------------------------------------------
The output has
-----------------------------------------------------------------------------------------
Obs Hdrrtyp Hdndate Hdntime hdnqty
1 H . 14:01:28.022838 1
-------------------------------------------------------------------------------------------------
Kindly give some solution for the above one
Thanks & Regards
Rohit
@rohitkrishna wrote:
my Req is to remove ifan symbol in the date
I don't know what "ifan symbol" means.
Nevertheless, when dealing with dates and times, you are much better off handling them as numbers (SAS date values and/or SAS time values and/or SAS datetime values) than dealing with them as character strings. The INPUT() function will convert these character strings to numbers for you, and then the FORMAT statement makes them appear understandable to humans.
Example:
data ls285;
infile cards;
Input @1 Hdrrtyp $char1.
@3 Hdndate $10. /* Header date */
@14 Hdntime $15. /* Header time */
@32 hdnqty 8.; /* Records in file */
hdndate1=input(hdndate,yymmdd10.);
hdntime1=input(hdntime,time.);
format hdntime1 time16.8 hdndate1 yymmdd10.;
cards;
H|2020-01-06T14:01:28.0228380Z|1
;
But even simpler, read the character strings in as SAS date/time values in one step using the proper informat, in this case the E8601dt informat.
data ls285a;
infile cards;
Input @1 Hdrrtyp $char1.
@3 Hdndatetime e8601dt26.6
@32 hdnqty 8.; /* Records in file */
format hdndatetime datetime24.6;
cards;
H|2020-01-06T14:01:28.0228380Z|1
;
Make your dates and times numbers as I explained. Then the yymmddn8. format shows no dashes.
What you have in your input data is a ISO 8601 formatted timestamp, for which SAS provides the e8601dz informat. Read your data with it, and extract date and time as needed. Then apply display formats as desired:
data want;
infile datalines dlm='|' dsd;
input hdrrtyp :$1. headertime :e8601dz28. hdnqty;
hdndate = datepart(headertime);
hdntime = timepart(headertime);
format
headertime e8601dz28.6
hdndate yymmddn8.
hdntime time8.
;
datalines;
H|2020-01-06T14:01:28.0228380Z|1
;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.