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: Call for Content

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!

Submit your idea!

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
  • 633 views
  • 2 likes
  • 3 in conversation