Newbie question about put option.

Accepted Solution Solved
Reply
Super Contributor
Posts: 418
Accepted Solution

Newbie question about put option.

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


Accepted Solutions
Solution
‎05-28-2014 12:18 PM
Respected Advisor
Posts: 3,799

Re: Newbie question about put option.

Posted in reply to Anotherdream

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


All Replies
Solution
‎05-28-2014 12:18 PM
Respected Advisor
Posts: 3,799

Re: Newbie question about put option.

Posted in reply to Anotherdream

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.

Super User
Posts: 19,772

Re: Newbie question about put option.

Posted in reply to Anotherdream

+(-1) between the variables.

data Testhutto;

set person;

file codeTest lrecl=20000 ;

put TestA +(-1) 'heyman';

run;

Super Contributor
Posts: 418

Re: Newbie question about put option.

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!

Super Contributor
Posts: 282

Re: Newbie question about put option.

Posted in reply to Anotherdream

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.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

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