BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
MaxOne
Calcite | Level 5

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

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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

View solution in original post

8 REPLIES 8
Reeza
Super User

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

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

MaxOne
Calcite | Level 5

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

I await for solution ..

Reeza
Super User

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

Cynthia_sas
SAS Super FREQ

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 $;) instructs SAS to read until a space (the default delimiter is encountered or the end of record mark is encountered.

 

cynthia

MaxOne
Calcite | Level 5

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

Reeza
Super User

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

Reeza
Super User

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

Tom
Super User Tom
Super User

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
;

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!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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