BookmarkSubscribeRSS Feed
PriyaB
Fluorite | Level 6

As i have created a data set to use numeric function like "INTCK" and "INTNX" but I don't know why my data is getting truncated although i have use length keyword still the data get truncated.

Can anyone please correct me where I am going wrong. This would be really helpful if anyone can explain so that the same mistake wont repeat again. Thanks in advance.

Regards,

Priya

 

1. Kindly find below screenshot for coding, Log and Output Result reference.

A. Coding section :

PriyaB_1-1712378330552.png

 

 

B. Log Section :

PriyaB_2-1712378355800.png

 

C. Output Result:

PriyaB_3-1712378384345.png

 

 

6 REPLIES 6
Ksharp
Super User
What kind of output would you like to see ?
Patrick
Opal | Level 21

We can help you best if you share your code with the data not as a screenshot but as text that we then can copy/paste as a starting point. 

Use the running man icon to post such code and data. Patrick_0-1712381785750.png

 

At least one of the issues with your current code:

You define a length for variable location which instructs SAS how to create the variable BUT it doesn't instruct SAS how to read source data. You need to define/use an INFORMAT for this.

 

In your input statement you're using INPUT ... location $ 

With this syntax SAS will only read the first 8 characters. Try and use INPUT ... location :$20. instead.

 

Tom
Super User Tom
Super User

@Patrick wrote:

...

You define a length for variable location which instructs SAS how to create the variable BUT it doesn't instruct SAS how to read source data. You need to define/use an INFORMAT for this.

 

In your input statement you're using INPUT ... location $ 

With this syntax SAS will only read the first 8 characters. Try and use INPUT ... location :$20. instead.

 


Your description of the impact of adding $ after LOCATION in the INPUT statement is wrong. 

 

A bare $ in an INPUT function merely gives SAS a hint that if the variable was not previously defined then to define it as character.  And with no other information about what length to set for the variable it will use $8.  But in this case the variable is already defined to have length $20.  So the $ in the INPUT statement does nothing at all.

 

The INPUT statement will read the next "word" from the line based on the current delimiter (the default is the space character).  Leading spaces will be ignored and the first 20 bytes will be stored into LOCATION.

FreelanceReinh
Jade | Level 19

Hello @PriyaB,

 

In addition to the insufficient length specifications, at least for variable STATION, mentioned by @Patrick (I disagree with his comment about "location $", though) there is the issue of embedded blanks in the character values -- assuming that the "JA digit sequence" part of your data lines is the intended value of STATION and the rest is for LOCATION.

 

It looks like the two values on each line are separated by two blanks (green rectangles below).

PriyaBs_datalines.png

But from a screenshot we can't tell for sure if a "blank" is an ordinary space character (ASCII code 32). Strangely enough, the two "blanks" (?) indicated by the red arrows above do not occur in the screenshot of your output -- which suggests that you created that output from slightly different data lines.

 

Character variable STATION is created with the default length of 8 bytes, but presumably ought to accommodate up to 16 characters. You increased the length of LOCATION to 20 bytes, but this is still insufficient for the 22-character string "MIYAKE-JIMA, TOKYO, JA" (or do you want to omit the "JA" at the end because it is redundant in a dataset named weather_japan?).

 

So, you could use

length station $16 location $22;
input station & location &;

The ampersand signs allow for the embedded single blanks in the values (see documentation INPUT: List), given the double-blank column separators.

 

Alternatively, you could integrate the length definitions into the INPUT statement by adding informat specifications and omit the LENGTH statement:

input station &:$16. location &:$22.;

(see again the INPUT: List documentation; this is modified list input)

 

or, similarly, with a more generous, common length definition for both variables:

input (station location) (&:$25.);

 

Astounding
PROC Star

As others have mentioned, the problem lies with your instructions to read in the data.  While @FreelanceReinh has shown some of the many choices you have available, the simplest (yet intuitive) way to read the data would be like this:

data weather_japan;
input station $ 1-17 location $ 18-40;
datalilnes;
... same datalines that you posted ...
;

You would have to do the work of telling SAS where to find the fields you are reading.  SAS will pull the data from the columns you specify.  

 

Also note, this style of inputting the data will left-hand justify whatever it finds so it won't matter whether LOCATION begins in column 18 or column 19.

 

Finally, this can't be your final data set.  There are no variables suitable for practicing the INTNX or INTCK functions

Cynthia_sas
SAS Super FREQ
Hi:
In the Programming 2 class, we have a SAS dataset called weather_japan.sas7bdat, so if you are working in that class, and with the demo program p203d03.sas, you would not need to create weather_japan because it already exists.
Can you clarify where in the Programming 2 class you are working and provide the title of the practice or demo you're trying to do?
Thanks,
Cynthia

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

LIBNAME 101

Follow along as SAS technical trainer Dominique Weatherspoon expertly answers all your questions about SAS Libraries.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 6 replies
  • 3865 views
  • 0 likes
  • 7 in conversation