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.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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