BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Belle
Obsidian | Level 7

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;

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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;

View solution in original post

2 REPLIES 2
Reeza
Super User

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;

Belle
Obsidian | Level 7

Thanks Reeza, It works now.

sas-innovate-2024.png

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.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 1147 views
  • 1 like
  • 2 in conversation