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

Hello everyone. I am trying to write code to a txt file, and in doing some I ran into an interesting question.


How do you write a vairable from a dataset to a file, concatenate with a string WITHOUT a space occuring between them?

Example, if you had the following code.

data person;
   infile datalines delimiter=',' dsd missover;
informat TESTA $300.;
   input TestA;
   datalines;
Testthis
one
one
ONe1
twoone
heyman
;


filename codeTest 'C:\urdesktop\codecreation.txt' ;
/*could use a data _null_ step here*/
data Testhutto;
set person;
file codeTest lrecl=20000 ;
put TestA'heyman';
run;

It would give you a text file that has the variable, folowed by a space, and then the string 'heyman'.

SO you would get.

Testthis heyman

one heyman

...

What I WANT is

TestthisHeyman

oneHeyman

...

I do not want the space (as the code has no space in it).  Does anyone know the option to get around this?

Thanks!

Brandon

1 ACCEPTED SOLUTION

Accepted Solutions
data_null__
Jade | Level 19

Pointer control.

put TestA +(-1) 'heyman';


When you use LIST-PUT as you have here SAS adds a space after the last value.  You just need to back up.

View solution in original post

4 REPLIES 4
data_null__
Jade | Level 19

Pointer control.

put TestA +(-1) 'heyman';


When you use LIST-PUT as you have here SAS adds a space after the last value.  You just need to back up.

Reeza
Super User

+(-1) between the variables.

data Testhutto;

set person;

file codeTest lrecl=20000 ;

put TestA +(-1) 'heyman';

run;

Anotherdream
Quartz | Level 8

Oh that's awesome! Thanks very much I will apply that across the places I want the varialbes!

This is exactly what I was looking for, thanks to both of your for your help!

Amir
PROC Star

Hi,

You could try "+(-1)":

data _null_;

  a='Hello';

  put a "world";

  put a +(-1) "world";

run;

giving:

Hello world

Helloworld

"+(-1)" tells the output pointer to go back one position.

Regards,

Amir.

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 4 replies
  • 994 views
  • 0 likes
  • 4 in conversation