BookmarkSubscribeRSS Feed
art_srap
Obsidian | Level 7

Dear SAS experts,
Is it possible to achieve this result output.png

without tranwrd (without removing 'UN' or other letters)? I need to have a dynamic code.
I started to solve on this way, but it didn't work yet. Thanks in advance.

 

data task_1;
input date: $9. ;

day=substr(date,1,2);
month=substr(date,3,3);
year=substr(date,6,4);


if (day) then day1=day;
if (year) then year1=year;
month1=put(month,3.);
if (month) then month1=month;
newdate=cats(year1,month1,day1);

datalines;
27APR2001
30JUL1979
unfeb2005
UNUNK1964
ununkunk
;

3 REPLIES 3
Kurt_Bremser
Super User

Please do not make use of dubious links. Post code, logs, and expected results directly here.

Use the "little running man" for code, </> for logs and textual data (or output), and the camera button for posting screenshots.

PGStats
Opal | Level 21
data task_1;
input date: $9. ;
length d m y $4 dateStr $10;
day=input(substr(date,1,2), ?? best.);
if day > 0 then d = put(day, z2.0);
month=whichc(upcase(substr(date,3,3)), 
	"JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC");
if month > 0 then m = put(month, z2.);
year=input(substr(date,6,4), ?? best.);
if year > 0 then y = put(year, z4.0);
dateStr = catx("-", y, m, d);
datalines;
27APR2001
30JUL1979
unfeb2005
UNUNK1964
ununkunk
;
PG
art_srap
Obsidian | Level 7

Thanks a lot.

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1163 views
  • 2 likes
  • 3 in conversation