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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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