BookmarkSubscribeRSS Feed
sarahzhou
Quartz | Level 8

Hi, 

I am new to SAS, I need help from you.

Is there a way to restore the order of mismatched observations?

 

Consider the following csv file,


PERSON_ID<|>DEPT_ID<|>DATE_JOINED
AAAAA<|>S1<|>2021
/01/03
BBBB
BB<|>S2<|>2021/02/03
CCCCC<|>S1<|>2021/03/05

 

I wish the output like,

 

desired_output.PNG

 

Thank you!

3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20

How 'messed up' is the file? Are any delimiters missing ?

Ksharp
Super User

It is really uneasy.

You need post real data to get pattern of starting a new line .

 

data have;
infile "c:\temp\temp.csv" lrecl=3000 length=len;
input have $varying3000. len;
if _n_=1 then delete;
if prxmatch('/^[a-z]{4,}/i',have) then group+1;
run;


data want;
 do until(last.group);
   set have;
   by group;
   length want $ 3000;
   want=cats(want,have);
 end;

length PERSON_ID DEPT_ID DATE_JOINED $ 100;
PERSON_ID=scan(want,1,'<|>');
DEPT_ID=scan(want,2,'<|>');
DATE_JOINED=scan(want,3,'<|>');
 drop have;
 run;

 

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

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