DATA Step, Macro, Functions and more

problem with blankspaces

Reply
Occasional Contributor
Posts: 8

problem with blankspaces

[ Edited ]

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?

Super User
Posts: 10,460

Re: problem with blankspaces

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.

Super User
Posts: 5,069

Re: problem with blankspaces

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?

Ask a Question
Discussion stats
  • 2 replies
  • 148 views
  • 0 likes
  • 3 in conversation