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;

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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