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

Hi everyone.

I am using SAS OnDemand for Academics. I am trying to make a simple data set using the following code 

data new;     
	input percent cPLTL $ @@;     
	cards;     
	2.19 cPLTL     
	17.03 non-cPLTL      
	;         
proc print data=new; run;  

which yields these results:

mcmaxwell_0-1632947499520.png

How do I specify the character length of the "cPLTL" variable so that the last L in "non-cPLTL" won't be cut off? I tried adding the number 9 after the $ in the input function, but then the Studio kept running the code and never produced any results...

Thanks!

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Best practice is to define the variable before using it so that SAS does not have to guess how you want it defined.

data new;     
  length percent 8 cPLTL $20 ;
  input percent cPLTL ;     
cards;     
2.19 cPLTL     
17.03 non-cPLTL      
;    

PS: Do not indent lines of in-line data.  To remind you not to intend the data do not indent the CARDS/DATATLINE statement either.

PPS: Do not insert physical tab characters into data lines. You also shouldn't be inserting tabs into lines of program code as they are invisible to humans and can end up in the middle of the lines and result in really strangely formatted code.  Instead take advantage of the editor's ability to translate you hitting the TAB key into inserting the correct number of spaces you like to use.

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

Best practice is to define the variable before using it so that SAS does not have to guess how you want it defined.

data new;     
  length percent 8 cPLTL $20 ;
  input percent cPLTL ;     
cards;     
2.19 cPLTL     
17.03 non-cPLTL      
;    

PS: Do not indent lines of in-line data.  To remind you not to intend the data do not indent the CARDS/DATATLINE statement either.

PPS: Do not insert physical tab characters into data lines. You also shouldn't be inserting tabs into lines of program code as they are invisible to humans and can end up in the middle of the lines and result in really strangely formatted code.  Instead take advantage of the editor's ability to translate you hitting the TAB key into inserting the correct number of spaces you like to use.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 444 views
  • 1 like
  • 3 in conversation