Unable to change data format - sas

I need to convert dates in the following forma:
30-giu-18
30-nov-20
......
into:
30JUN2018
30NOV2020
.......
I tried:
data Test;
set input;
mydates = input(myolddates, ddmmyy10.;)
format mydates ddmmyy10.;
run;
It doesn't work. The variable myolddates is character $9.
Can anyone help me please?

Try this
data have;
input myolddates $9.;
datalines;
30-giu-18
30-nov-20
;
options dflang = Italian ;
data want;
set have;
date = input(myolddates, EURDFDE9.);
format date ddmmyy10.;
run;

Related

SAS group by first digits

I have a variable in SAS with a lot of numbers, for example 11000, 30129, 11111, 30999. I want to group this by the first two digits so "11000 and 11111" and "30129 and 30999" will be in a own table.
It's quite simple,
You have to create a second column and extract the 2 first digit.
Then sort the dataset by this second columns.
data test;
infile datalines dsd ;
input a : 15. ;
datalines;
11000,
30129,
11111,
309999,
;
run;
data test_a;
length val_a $2;
set test;
val_a= SUBSTRN(a,1,2);
run;
proc sort data=test_a out=test_b;
by val_a;
run;
Result will be :
val_a a
11 11000
11 11111
30 30129
30 309999
And then you can create 2 dataset with selection on the val_a like this :
data want data_11 data_30;
set test_b;
if val_a = 11 then output data_11;
if val_a = 30 then output data_30;
run;
Regards,
I think I did like you, but my new column only shows with ".". But I think your answer can give me some help anyways, thank you!
data books;
infile "&path\Boken.csv" dlm=';' missover dsd firstobs=2;
input ISBN: $12.
Book: $quote150.;
run;
data test_a;
format val_ISBN 15.;
set books;
val_ISBN= SUBSTRN(ISBN,1,2);
run;
proc sort data=test_a out=test_b;
by val_ISBN;
run;
proc print data=test_b (obs=10) noobs ;
run;

SAS PRXPARSE usage to retrieve length of string matching pattern

I have to retrieve the X-Axis and Y-Axis pos from ADDITIONAL_DETAILS field which is more than 300 bytes in length.
Somewhere in this string, I am getting the location details as RETLOCID=2312.4892 like that.
I am trying to use PERL REGEX in SAS.
Problem: I am able to get the starting position into postn1 from call prxsubstr(MATCH_PATTERN1, ADDITIONAL_DETAILS, postn1,length1); but the length is always returned as 8 even though it is more than that.
TRANSACTION_ID = substrn(ADDITIONAL_DETAILS, postn1, length1); This is not giving me proper value when I am restricting length to 8. Any help is appreciated. Below is the code:
DATA WORK.LOCATION;
INFILE DATALINES;
INPUT ADDITIONAL_DETAILS $50.;
datalines;
afdsf RFTXNID=121.5435 xx
fdsg RFTXNID=7821.5487 xx fdsg
gfdgf
;
RUN;
data WORK.POSITION;
set WORK.POSITION;
if _N_ = 1 then do;
MATCH_PATTERN1 = PRXPARSE("/(RETLOCID=)/");
MATCH_PATTERN2 = PRXPARSE("/([0-9]{1,}\.[0-9]{1,})/");
end;
retain MATCH_PATTERN1 MATCH_PATTERN2;
call prxsubstr(MATCH_PATTERN1, ADDITIONAL_DETAILS, postn1,length1);
call prxsubstr(MATCH_PATTERN2, ADDITIONAL_DETAILS, postn2,length2);
if postn1 > 0 and not missing(ADDITIONAL_DETAILS) then
TRANSACTION_ID = substrn(ADDITIONAL_DETAILS, postn1 + 8, length1);
RUN;
data work.POSITION;
set work.POSITION;
drop MATCH_PATTERN1 postn1 length1;
run;
I need to pull 121.5435 and 7821.5487
Try this:
DATA WORK.LOCATION;
INPUT ADDITIONAL_DETAILS $50.;
string=prxchange('s/[a-z=_]+//i',-1,ADDITIONAL_DETAILS);
datalines;
afdsf RFTXNID=121.5435 xx
fdsg RFTXNID=7821.5487 xx fdsg
DISTR_QUOTE=66.92
gfdgf
;
run;
Or
DATA WORK.LOCATION;
INPUT ADDITIONAL_DETAILS $50.;
length string $20.;
if prxmatch('/\=/',ADDITIONAL_DETAILS)=0 then string='';
else string=prxchange('s/.*(?<=\=)([^a-z]+).*/$1/i',-1,ADDITIONAL_DETAILS);
datalines;
afdsf RFTXNID=121.5435 xx
fdsg RFTXNID=7821.5487 xx fdsg
gfdgf
DISTR_QUOTE=66.92
;
proc print;
run;

SAS proc format for background colours for dates including blank values

I have this code where I create a proc format statement for dates based on todays date.
Any date prior to today is red and any date in the future is green. However this is a proc report I am calling this statement in and there are blank values for date in some cases. Therefore, I want fields that don't contain a date to be white.
data _null_;
sdate = date ();
format sdate date9.;
call symput('sdate',sdate);
run;
proc format;
value closefmt
low - &sdate ='red'
' ' = 'white'
&sdate - high = 'green';
run;
It doesn't like ' ' = white and doesn't accept null.
Any help would be appreciated.
Thanks in advance.
Use single dot for missing values in numeric variable:
proc format;
value closefmt
low - &sdate ='red'
. = 'white'
&sdate - high = 'green';
run;
/* test code */
data indata;
d = .; output;
do i=-3 to 3;
d = today()+i;
output;
end;
run;
data _null_;
set indata;
format d yymmdds10.;
length color $10;
color = put(d, closefmt. - L);
putlog d color;
run;

SAS programming : Convert Exponential value to numeric value in SAS

How to convert exponential(for eg. 3.22254e2, 3.24456545e-3) values to numeric format(322.254,0.00324456545) in SAS. I am getting the source as varchar from a file and need to store the same in oracle as number format.
I need to read from a file(csv) so When i tried to do the same i get the result(b) as null.
My code:
data work.exp_num ;
infile 'exp_number.csv'
lrecl = 256
delimiter = '~'
dsd
missover
firstobs = 2;
;
attrib a length = $300
format = $32.
informat = $32.;
input a ;
run;
data test;
set work.exp_num;
b=input(a,32.16);
run;
Kindly help.
Thanks in advance.
You can use the standard informat w.d .
Here you got an example:
data test;
a='3.24456545e-3'; output;
a='3.22254e2'; output;
run;
data erg;
set test;
b=input(a,32.16);
run;

Changing date format in SAS9.3

Does anyone know how to change a date variable from Date9 to MMDDYY10 format in SAS9.3? I've tried using the put and input functions, but the result is null
Formats are nothing but instructions on how to display a value. Dates are numeric represented as the number of days from 1JAN1960.
data x;
format formated1 date9. formated2 mmddyy10.;
noformated = "01JAN1960"d;
formated1 = noformated;
formated2 = noformated;
run;
proc print data=x;
run;
Obs formated1 formated2 noformated
1 01JAN1960 01/01/1960 0
In short, just change the format on the dataset and the date will be displayed with the new format.
Try both functions:
tmpdate = put(olddate,DATE9.);
newdate = input(tmpdate,MMDDYY10.);
Or maybe even
newdate = input(put(olddate,DATE9.),MMDDYY10.);
For changing the format of variable in a table - PROC SQL or PROC DATASETS:
data WORK.TABLE1;
format DATE1 DATE2 date9.;
DATE1 = today();
DATE2 = DATE1;
run;
proc contents;
run;
proc datasets lib=WORK nodetails nolist;
modify TABLE1;
format DATE1 mmddyy10.;
quit;
proc sql;
alter table WORK.TABLE1
modify DATE2 format=mmddyy10.
;
quit;
proc contents;
run;