Hello,
I have a big SAS dataset that has 5m records with 160 variables. I want to create a txt file and then create a zip file of it so I can send to others.
Here is what I did:
1. Created a macro variable for txt file header called &flat_head. Here is how it look like: ID|F_name|L_name|Age|DOB|Zip_code|City|........
2. Created a macro variable &putvar for put step: ID F_name L_name Age DOB Zip_code City|
3. Created a txt file using these two macro variables.
However, I'm not sure which step I did wrong. program did not work.
Any suggestions on this?
Thank you in advance.
proc contents data = file noprint
out = test(keep=name rename=(name=varname));
run;
Proc sql noprint;
select varname into: Flat_head separated by '|'
from test;
%put flat_head=&flat_head.;
Data test2;
Set test END=LAST;
Length putvar $1000;
IF _N_ EQ 1 Then putvar='';
putvar=Trim(putvar)||' '||Trim(varname);
Retain putvar;
IF LAST Then Call Symput('putvar', Trim(putvar));
Run;
%Put putvar=&putvar.;
data _NULL_;
SET file END=EOF;
FILE FLATOUT DELIMITER='|' DSD;
IF _N_=1 THEN PUT "&Flat_head.";
PUT &putvar.;
IF EOF THEN PUT "TOTAL NUMBER OF RECORDS = " _N_;
RUN;
Where did you define flatout and there is no quit for your sql statement.
Also, why the data step for the second macro variable not another sql step?
proc contents data = file noprint
out = test(keep=name rename=(name=varname));
run;
Proc sql noprint;
select varname into: Flat_head separated by '|'
from test;
select varname into: putvar separated by " "
from test;
quit;
%put flat_head=&flat_head.;
%put put_var=&put_var.;
data _NULL_;
SET file END=EOF;
FILE 'C:\temp\test.txt' DELIMITER='|' DSD;
IF _N_=1 THEN PUT "&Flat_head.";
PUT &putvar.;
IF EOF THEN PUT "TOTAL NUMBER OF RECORDS = " _N_;
RUN;
Where did you define flatout and there is no quit for your sql statement.
Also, why the data step for the second macro variable not another sql step?
proc contents data = file noprint
out = test(keep=name rename=(name=varname));
run;
Proc sql noprint;
select varname into: Flat_head separated by '|'
from test;
select varname into: putvar separated by " "
from test;
quit;
%put flat_head=&flat_head.;
%put put_var=&put_var.;
data _NULL_;
SET file END=EOF;
FILE 'C:\temp\test.txt' DELIMITER='|' DSD;
IF _N_=1 THEN PUT "&Flat_head.";
PUT &putvar.;
IF EOF THEN PUT "TOTAL NUMBER OF RECORDS = " _N_;
RUN;
Thanks Reeza, It works now.
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.