BookmarkSubscribeRSS Feed
dan12345
Calcite | Level 5

here is the deal: I am creating a table with some variables and the 'observations' are read from a .txt file here is my code f

 

data pesek;
    infile 'a path'
    input id kon $ alder utb $@@;
run;

  

ok that works out fine however it is adding a blankspace to each observation in my variable 'utb' which is a problem. If I now add data to this existing table with the INPUT statement  for example  I add: 29 M 20 GY  it will not create extra blankspace to GY which means that any observation in my table which has GY+blankspace will not be "the same" as the GY which I added with the input statement since one has the blankspace and the other one doesnt 

 

what can I do?

2 REPLIES 2
ballardw
Super User

It is very hard to resolve a data reading issue without example data. Provide a few lines of data.

 

Also, how are you "adding" data? Append, merge, update or something else? I'm pretty sure I don't understand your limitation/problem as stated.

Astounding
PROC Star

It sounds like you have a few misconceptions.  Consider these basic concepts.

 

Both KON and UTB have a length of 8 characters.  That's the default length assigned for the style of INPUT statement that you are using.

 

When you refer to a variable, trailing blanks don't matter.  These statements always find the same matches:

 

if utb='GY' then do;

if utb='GY     ' then do;

 

When SAS detects that it is comparing character strings that have different lengths, it automatically pads the shorter string with blanks to make the lengths equal.  (That is, for purposes of making the comparison ... it is not actually changing the values of any variables.)

 

Does that change the questions that you want to ask?

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!

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
  • 685 views
  • 0 likes
  • 3 in conversation