data Have;
infile datalines delimiter='#';
input Comments : $200. ;
datalines;
UGESTAGE=34 5/7 WKS #
UPREM, UGESTAGE = 32WKS #
UGESTAGE =33.4 WKS #
GASTROJEJUNOSTOMY DEPENDENCE, BILATERAL GRADE 4 VU
;
run;
data Want;
infile datalines delimiter='/';
input UGESTAGE ;
datalines;
34 /
32 /
33 /
;
run;
I use Chrome, all the function icons are shown again. I think the previous IE was too old.
You should be able to post program code in either a text box or code box opened by clicking on the <> or "running man" icons that appear above the message window (7th and 8th from left to right).
It is possible this is what you meant/wanted to post. Is the first data step correct? or should there be 3 lines of USESTAGE=?
data Have; infile datalines delimiter='#'; input Comments : $200. ; datalines; UGESTAGE=34 5/7 WKS # UPREM, UGESTAGE = 32WKS # UGESTAGE =33.4 WKS # GASTROJEJUNOSTOMY DEPENDENCE, BILATERAL GRADE 4 VU ; run; data Want; infile datalines delimiter='/'; input UGESTAGE ; datalines; 34 / 32 / 33 / ; run;
Are you sure that Want data set contains what you really want? It only has the value of 34 for one record.
I'm really not good at all with RegEx but I would like to be. This may work with some of your data until you have a different pattern that breaks it. But maybe it will get you started.
data extracted;
set have;
pattern = prxparse ("/(?<=[=|= ])\d\d(\.[0-9]{1,2})?/");
call prxsubstr (pattern, comments, start, length);
if start gt 0 then do;
ugestage = substr(comments, start, length);
output;
end;
keep ugestage;
run;
proc print data = extracted;
run;
gives me
Obs | ugestage |
---|---|
1 | 34 |
2 | 32 |
3 |
33.4 |
data Have;
infile datalines delimiter='#';
input Comments : $200. ;
datalines;
UGESTAGE=34 5/7 WKS #
UPREM, UGESTAGE = 32WKS #
UGESTAGE =33.4 WKS #
GASTROJEJUNOSTOMY DEPENDENCE, BILATERAL GRADE 4 VU
;
run;
data Want;
infile datalines delimiter='/';
input UGESTAGE ;
datalines;
34 /
32 /
33 /
;
run;
I use Chrome, all the function icons are shown again. I think the previous IE was too old.
Do your example strings really start with four leading spaces like you have in your lines of in-line data?
If so your input statement that is using the normal $ informat will remove those leading spaces. To preserve the leading spaces you need to read the lines using $CHAR. Or copy the values from the _INFILE_ automatic variable after executing the INPUT statement.
data Have;
infile datalines delimiter='#';
input @'UGESTAGE' temp : $200. @@ ;
UGESTAGE=scan(temp,1,'.','kd');
datalines;
UGESTAGE=34 5/7 WKS #
UPREM, UGESTAGE = 32WKS #
UGESTAGE =33.4 WKS #
GASTROJEJUNOSTOMY DEPENDENCE, BILATERAL GRADE 4 VU
;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.