Hi Everyone,
I have a data with variable nameID as below.
I want to create separate file for each name AND the NameID colum is deleted from the final file.
Then export each file into CSV.
So the CSV file only contain var1 var2 (in the below dataset)
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
;
Use FILEVAR= on the FILE statement to create your csv (example under Windows) :
data have;
input name_ID var1 var2;
datalines;
111 1 2
111 3 6
111 6 9
555 2 2
555 4 5
555 5 4
563 2 2
563 1 1
;
%let path=&sasforum.\Datasets;
data _null_;
set have;
myFilename = cats("&path.\", name_ID, ".csv");
file toto filevar=myFilename dsd;
put var1 var2;
run;
Hello,
Here is a code that can help.....
data have;
input name_ID:$4. var1:$1. var2:$2.;
datalines;
1111 2
111 3 6
111 6 9
555 2 2
555 4 5
555 5 4
563 2 2
563 1 1
;
run;
proc sql;
create table t1 as select distinct name_ID from have;
quit;
proc print data=t1;
%macro names;
data &dsname;set have;where name_id = "&nameid";
%mend names;
data have;
set t1;
call symput('nameid',name_id);
call symput ('dsname',("_"||name_id));
call execute ('%names');
run;
proc contents data=work._all_;
Since the values of the name_id are numbers, I have added an underscore in the beginning to allow SAS to create dataset with Char in the beginning... At the end, here is what it creates... Rows 11-14 is what you are interested in.
# Name Member Type File Size Last Modified
1 DATA1 DATA 128KB 10/31/2015 01:04:53
2 DATA2 DATA 128KB 10/31/2015 01:06:30
3 DATA3 DATA 128KB 10/31/2015 01:08:38
4 DATA4 DATA 128KB 10/31/2015 01:11:19
5 HAVE DATA 128KB 10/31/2015 01:23:56
6 NAMEID DATA 128KB 10/31/2015 01:01:31
7 REGSTRY ITEMSTOR 32KB 10/31/2015 00:32:05
8 SASGOPT CATALOG 12KB 10/31/2015 00:32:49
9 SASMAC1 CATALOG 188KB 10/31/2015 00:32:10
10 T1 DATA 128KB 10/31/2015 01:23:55
11 _111 DATA 128KB 10/31/2015 01:23:56
12 _1111 DATA 128KB 10/31/2015 01:23:56
13 _555 DATA 128KB 10/31/2015 01:23:56
14 _563 DATA 128KB 10/31/2015 01:23:56
Hope it helps someway.... Good luck...!!!
Thank you, Kannad for helping me.
HC
Use FILEVAR= on the FILE statement to create your csv (example under Windows) :
data have;
input name_ID var1 var2;
datalines;
111 1 2
111 3 6
111 6 9
555 2 2
555 4 5
555 5 4
563 2 2
563 1 1
;
%let path=&sasforum.\Datasets;
data _null_;
set have;
myFilename = cats("&path.\", name_ID, ".csv");
file toto filevar=myFilename dsd;
put var1 var2;
run;
Thank you, PG.
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 var1 var2 ;
run;
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.
Ready to level-up your skills? Choose your own adventure.