Write and run SAS programs in your web browser

problem with length of variable when using INPUT WITH DATALINES in SAS STUDIO ON DEMAND 3.6

Accepted Solution Solved
Reply
New Contributor
Posts: 3
Accepted Solution

problem with length of variable when using INPUT WITH DATALINES in SAS STUDIO ON DEMAND 3.6

When I try to get the size of a char variable, I have to return the size plus 1.

The variable size is wrong !!!

This is a bug ?

 

More details in file atached ..

 


Accepted Solutions
Solution
2 weeks ago
Grand Advisor
Posts: 16,378

Re: problem with length of variable when using INPUT WITH DATALINES in SAS STUDIO ON DEMAND 3.6

Notice the HEX shows this. 09 - which is tab - at the front of every variable. 

View solution in original post


All Replies
Grand Advisor
Posts: 16,378

Re: problem with length of variable when using INPUT WITH DATALINES in SAS STUDIO ON DEMAND 3.6

What happens if you use a HEX Format on the variable? 

I suspect there's a 'invisible blank' in your data somehow. 

New Contributor
Posts: 3

Re: problem with length of variable when using INPUT WITH DATALINES in SAS STUDIO ON DEMAND 3.6

Thanks, I did try resset the code and data, but the problem not resolved yet.

I await for solution ..

Grand Advisor
Posts: 16,378

Re: problem with length of variable when using INPUT WITH DATALINES in SAS STUDIO ON DEMAND 3.6

I suspect the extra 1 is the Windows end of line character. On Demand is Unix system. 

SAS Super FREQ
Posts: 8,645

Re: problem with length of variable when using INPUT WITH DATALINES in SAS STUDIO ON DEMAND 3.6

[ Edited ]

Hi:

  When you code the NAME $20. in the INPUT statement, you are probably reading the end of record marker for the DATALINES. There is a very simple way to change that. Please see the attached examples. Altering your INPUT statement and adding a LENGTH statement results in both operating systems having the same length, as shown below.

correct_lengths_change_INPUT.png

 

Basically, the LENGTH statement specifies the MAXIMUM length for the variable and establishes the size of the variable in the descriptor portion of the dataset and the simplified LIST input statement (INPUT NAME $Smiley Wink instructs SAS to read until a space (the default delimiter is encountered or the end of record mark is encountered.

 

cynthia

New Contributor
Posts: 3

Re: problem with length of variable when using INPUT WITH DATALINES in SAS STUDIO ON DEMAND 3.6

code.jpg

 

The code below is with < TAB >

 

 

length_error.jpg 

code without <TAB>

 

code_correct.jpg

 

Now, works correctly

 

Output_Data.jpg

 

You are correct !!!
The problem was have Displaced this items in editor with the < TAB >, when I move left this items to left with <BACKSPACE> this problem was resolved.

 

Thank you very much ...

Solution
2 weeks ago
Grand Advisor
Posts: 16,378

Re: problem with length of variable when using INPUT WITH DATALINES in SAS STUDIO ON DEMAND 3.6

Notice the HEX shows this. 09 - which is tab - at the front of every variable. 

Grand Advisor
Posts: 16,378

Re: problem with length of variable when using INPUT WITH DATALINES in SAS STUDIO ON DEMAND 3.6

I can't replicate your issue on On Demand. I did test it SAS On Demand, not SAS UE or SAS Studio installed on my desktop. 

 

I get the correct values, but I'm on a Unix system (a Mac). I strongly suspect the invisible character issue mentioned earlier. Post the output using the hex editor.  I've added the relevant code below. 

 

In the future post your output directly into the forum, not with an attachment, many users won't bother to download an attachment so it takes longer to get answers since they simply won't respond or will wait for you to post directly to the forum.

 

 

 data WRONG_LENGTH;
 Input Name $20. ;
 v_length=length(name) ;
 y=put(name, hex20.);
 datalines  ;
 Anna  
 Christopher  
 Mary  
 Jonathan  
 Tim  
 Elizabeth  
 Amy  
 schwarzenegger  
 Kevin  
 Porter       
 ; 
 RUN ;

Screen Shot 2017-05-14 at 12.39.24 PM.png

Super User
Super User
Posts: 5,980

Re: problem with length of variable when using INPUT WITH DATALINES in SAS STUDIO ON DEMAND 3.6

In your word doc it looks like you have TABS at the beginning of your data lines.

	datalines;
	Anna
	Christopher
	;

You can probably avoid making this mistake again if you remember to always start the DATALINES (or CARDS) statement in column one so the SAS editor will default to starting the actual lines of data in column one also.

datalines;
Anna
Christopher
;
Post a Question
Discussion Stats
  • 8 replies
  • 123 views
  • 0 likes
  • 4 in conversation