Create seperate file for each Name (ID)

Accepted Solution Solved
Reply
Super Contributor
Posts: 371
Accepted Solution

Create seperate file for each Name (ID)

Hi Everyone,

I have a data with variable nameID as below.

I want to create separate file for each name.

Then export each file into CSV.

There are thousand names and I haven't found a way to do it yet.

Any help is very much appreciated.

HHC

data have;

input name_ID var1 var2;

datalines;

1111 2

111 3 6

111 6 9

555 2 2

555 4 5

555 5 4

563 2 2

563 1 1

;


Accepted Solutions
Solution
‎09-08-2014 09:18 AM
Grand Advisor
Posts: 9,567

Re: Create seperate file for each Name (ID)

data have;
input name_ID var1 var2;
datalines;
1111 2
111 3 6
111 6 9
555 2 2
555 4 5
555 5 4
563 2 2
563 1 1
;
proc sort data=have;by      name_ID; run;
data _null_;
 set have;
 fname=cats('c:\temp\File_',name_ID,'.csv');
 file dummy filevar=fname dsd;
 put (_all_) (:);
run;

Xia Keshan

Message was edited by: xia keshan

View solution in original post


All Replies
Grand Advisor
Posts: 17,313

Re: Create seperate file for each Name (ID)

Write the code manually for one file, or use proc import and get the code.

Then change it to use the FILEVAR option in a data _null_ step.

http://www.lexjansen.com/mwsug/1999/paper03.pdf

Solution
‎09-08-2014 09:18 AM
Grand Advisor
Posts: 9,567

Re: Create seperate file for each Name (ID)

data have;
input name_ID var1 var2;
datalines;
1111 2
111 3 6
111 6 9
555 2 2
555 4 5
555 5 4
563 2 2
563 1 1
;
proc sort data=have;by      name_ID; run;
data _null_;
 set have;
 fname=cats('c:\temp\File_',name_ID,'.csv');
 file dummy filevar=fname dsd;
 put (_all_) (:);
run;

Xia Keshan

Message was edited by: xia keshan

Super Contributor
Posts: 371

Re: Create seperate file for each Name (ID)

Thank you Xia and Reeza for helping me.

HHC

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 206 views
  • 3 likes
  • 3 in conversation