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

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 1175 views
  • 1 like
  • 2 in conversation