The following program in SAS EG 9.3 is giving me results as below:
DATA work.header;
calculation='"A00",'
||'"399",'
|| '"NOM",'
|| PUT(DATE(), yymmddn8.)
||","
||put(time(),hhmm8.2);
Run;
Results I'm getting as below:
"A00","399","NOM",20141028,10:03.76
However I would like the time to be "100345" like hhmmss?
Any help would be appreciated.
The format to use is TIME8., which will give you a time of the format HH:MM:SS
e.g.
put(time(),time8.);
Gives:
10:46:40
To remove the colons from this, you'll have to use string functions, I would go for:
compress(put(time(),time8.),'','dk');
Which only keeps the numeric characters, giving:
104640
Related
I'm developing a data fusion pipeline. It contains a wrangler node where I'm trying to create a new field that will contain the system date in timestamp format (yyyy-MM-dd'T'HH-mm-ss).
I've tried using the sentence:
set-column :sysdate (${logicalStartTime(yyyy-MM-dd'T'HH-mm-ss)})
But I receive the error:
Caused by: io.cdap.wrangler.api.DirectiveParseException: Error encountered while parsing 'set-column' : Error encountered while compiling '( 2022 -12-01T16-29-32 ) ' at line '1' and column '14'. Make sure a valid jexl transformation is provided.
Which would be the correct sentence?
I've tried:
set-column :sysdate (${logicalStartTime(yyyy-MM-ddHH-mm-ss)})
Which will result in something like "1877", as it substracts the numbers, and also tried:
set-column :sysdate (${logicalStartTime(yyyyMMddHHmmss)})
but the format isn't correct and can only be written if the field is a String.
You have the correct method, just incorrect syntax. The syntax you are looking for is set-column :sysdate ${logicalStartTime(yyyy-MM-dd'T'HH-mm-ss)}, you have to remove (). Then you can convert the string in datetime pattern in this format parse-as-datetime :sysdate "yyyy-MM-dd'T'HH-mm-ss".
I have a variable DRG in my dataset and I would like to create a new variable with the second and third characters in the DRG string. For example, if DRG value is A23B I would like to extract 23 as a new variable.
Can someone please help me with the SAS code. Thanks a lot in advance.
Sample code
data example;
input DRG $4.;
cards;
A23B
A13A
A45C
B82B
B82C
B34A
C01A
C25B
C46B
;
run;
Thanks for the help.
I was able to work out the answer by following this webpage https://www.listendata.com/2017/03/extract-last-4-characters-digits-in-sas.html
Here is my code:
data example2;
set example;
want = substr(DRG,length(DRG)-2,2);
run;
I am new to SAS. I was trying to print only rows where the string size is less than 20, for the column words. I tried this, but that doesn't work. What is the right syntax?
FILENAME REFFILE '<path_to_the_file>';
...
PROC PRINT DATA=WORK.IMPORT;
WHERE length("words") < 20;
RUN;
This is the error I get
ERROR: Invalid characters were present in the data.
ERROR: An error occurred while processing text data.
I don't think there is any problem with the data itself, as the following works fine.
PROC PRINT DATA=WORK.IMPORT;
WHERE words = "some string";
RUN;
As it turned out, the problem was not with the code itself, but because I did not specify the encoding. So instead of
FILENAME REFFILE '<path_to_the_file>';
I used the following, which worked.
FILENAME REFFILE '<path_to_the_file>' encoding="latin1";
Here is my scenario. I am getting this date from a database:
11-AUG-15 10.38.00.000000000 AM
Is there any way to format this string to look something similar to mm/dd/yy?
So far I have tried the following with no luck:
DateFormat()
CreateODBCDate()
LSParseDateTime()
Every time I use one of the above, I get the following error:
11-AUG-15 10.38.00.000000000 AM is an invalid date or time string.
Any advise will be greatly appreciated.
Thanks!
parseDateTime("11-AUG-15 10.38.00.000000000 AM", "dd-MMM-yy hh.mm.ss.S aa");
Run me: http://trycf.com/gist/aac6d63777ae1b0e9aa3/acf?theme=monokai
Then you are free to use DateFormat() or DateTimeFormat()to format the date object.
The NEGPARENw.d reads the values -2000 as (20,00) based on the w.d
is there anyway to do the same in SAS 9.1?
I read a value 00005000- as character value and then converted to numeric value
-5000
TEMP=000005000-
Temp= COMPRESS(TEMP,'-')
TEMP=-(INPUT(TEMP,16.2)) format NEGPARENw.d its not working
PRoc report;
.....
define temp /display format = NEGPAREN16.2
Run;
Thanks
NEGPARENw.d format exists in 9.1.3, so there's no particular reason it wouldn't work the same in 9.1.3 as it would in later versions.