BookmarkSubscribeRSS Feed
thaboseja_gmail_com
Calcite | Level 5

Good day,

 

THE BELOW OUTPUT IS FROM THIS MACRO 

%MACRO ds2pipe1(dsname, outfile, title1=, title2=,mod=N,date=N,printLabels=N,zip=N);
DATA _NULL_;
SET WOOLWORTHyday_;
RUN;
DATA _NULL_;
RUN;
/*options noxwait; */
filename data temp;
proc contents data=&dsname noprint
out=_tmp_;
run;

proc sort data=_tmp_;
by varnum;
run;

* to cater for no more than 100 vars;
data _null_;
length name label text $300;
set _tmp_ end=eof;
file data;
if type=2 then
/*rather export all as quote delimitted to be on the safe side;*/
name=name;
if eof then put name ');put info1;';
else if _n_=1 then do;
put 'info1= STRIP(' name'||"#"||';
/*put 'info1= (' name '||""||';*/
end;
else do;
put 'STRIP(' name ')||"#"||';
/*put '(' name ')||""||';*/
end;
run;

data _null_;
file "&outfile..txt" ls=32767
%if "&mod"="Y" %then %do;
mod
%end;;
set &dsname end=eof;
if _n_=1 then do;
if "&title1" ^="" then do;
put "&title1";
put ;
%if "&title2"^="" %then %do;
put "&title2";
%end;
put ;
end;

/*%include header;*/
end;
%include data;
%if "&date"="Y" %then %do;
if eof then do;
put ;
_tod=today();
put "Date printed: " _tod yymmdd10.;
end;
%end;
run;
%if "&zip"="Y" %then %do;

/*options nowait;*/
data _null_;
rc=system('zip '||"&outfile..zip &outfile..txt");
run;
%end;
proc datasets mt=data lib=work nolist nodetails;
delete _tmp_;
quit;

%mend;

 

OUTPUT

14C#04799#0000011832#0000000000#00641934#0007406199999909#001#KKKONI________#ZZ____#000007000341#000000000M00223353#00000000#000563500.00#000524551.07#00000000#0240#000004996.38#000000000000 '65 BLANKS'                                                             

 

 AFTER THE LAST CHAR I WANT TO PUT MORE 65 BLANK SPACE 

 

 

 

6 REPLIES 6
RW9
Diamond | Level 26 RW9
Diamond | Level 26

What is it your trying to do, post test data in the form of a datastep and what the output should look like.  The reason is that your code here doesn't make much sense.  Just take the first two data steps - these don't do anything, data _null_ doesn't create any output, so the code is pointless.  I am finding it very difficult to read the rest of the code which has varying mixed case, no indentations and macro code for no apparent reason.

thaboseja_gmail_com
Calcite | Level 5
hi,can you put blank char and export data with txt

hi below is the data
14C#04799#0000011832#0000000000#00507774#0008204125200089#001#ABRAHAMS______#I_____#000007045820#000000000M00950189#00000000#000035000.00#000033230.18#00000000#0360#000000307.91#000000000000


put 'info1= STRIP(' name'||"#"||';
/*put 'info1= (' name '||""||';*/
end;
else do;
put 'STRIP(' name ')||"#"||';
/*put '(' name ')||""||';*/
i used strip function to remove spaces and i also used # to separate data.the data for the first column is 14C and the last data is 000000000000
from the first column to the last data is 191 in length ,so after this 000000000000 i want to add 65 more blank spaces.
RahulG
Barite | Level 11

I agree that it is unclear what you need. 

 

Below tip can help you to add multiple spaces 

 

 

data _null_;
put "START"   65*' '    "END";
run;

 

 

65* ' ' would insert 65 blank spaces between START and END

thaboseja_gmail_com
Calcite | Level 5

hi below is the data

14C#04799#0000011832#0000000000#00507774#0008204125200089#001#ABRAHAMS______#I_____#000007045820#000000000M00950189#00000000#000035000.00#000033230.18#00000000#0360#000000307.91#000000000000

 

 

put 'info1= STRIP(' name'||"#"||';
/*put 'info1= (' name '||""||';*/
end;
else do;
put 'STRIP(' name ')||"#"||';
/*put '(' name ')||""||';*/

i used strip function to remove spaces and i also used # to separate data.the data for the first column is  14C and the last data is 000000000000

from the first column to the last  data is 191 in length ,so after this  000000000000 i want to add 65 more blank spaces.

Tom
Super User Tom
Super User

I really am having a hard time telling if you want to write all of those characters on one line or on multiple lines.

If you are writing to a text file using a DATA step and a PUT statement and you want the lines to be exactly 191 characters long you can just put a space in column 191.

 

Try running this litte program and you will see that the second line is 65 characters long.

 

filename example temp;
data _null_;
  file example lrecl=32767 ;
  put 'This is a line';
  put 'This is a line with many spaces' @65 ' ';
run;
data _null_;
  infile example;
  input;
  list;
run;

 

 If instead you want to add spaces instead then use the + for cursor movement instead of @ .

put 'some text' +64 ' ';

Note that the value used in both the + and @ can be a reference to a data set variable.

strng='stuff to write';
extra_spaces = 191-length(string);
put string +extra_spaces ' ';

 

 

Tom
Super User Tom
Super User

 

Please explain what you are trying to do. It is probably easier to just have the DATA step write the data in the form you need.

So let's say your actual data looks like this simple data file.

data have ;
  input string $50.;
cards;
14C
04799
0000011832
0000000000
00641934
0007406199999909
001
KKKONI________
ZZ____
000007000341
000000000M00223353
00000000
000563500.00
000524551.07
00000000
0240
000004996.38
000000000000
;

If you want to write that out to one line with # between the values and an extra 65 blanks after the last value then you could use this data step.  The +(-1) will back up over the # delimiter that the PUT automatically generates before a new value when using DSD option.

data _null_;
  file example dsd dlm='#' lrecl=32767 ;
  set have end=eof ;
  put string @ ;
  if eof then put +(-1) 65*' ';
run;

 

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!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 6 replies
  • 1304 views
  • 0 likes
  • 4 in conversation