BookmarkSubscribeRSS Feed
User_Help
Obsidian | Level 7

i have a list of data, how can i input to capture properly?

 

data test;

     input title $ 1-26 year type $;
     datalines;
     A Midsummer Night's Dream 1595 comedy
     Comedy of Errors 1590 comedy
     Hamlet 1600 tragedy
     Macbeth 1606 tragedy
     Richard III 1594 history
     Romeo and Juliet 1596 tragedy
     Taming of the Shrew 1593 comedy
     Tempest 1611 romance
;
run;

7 REPLIES 7
PeterClemmensen
Tourmaline | Level 20

Hi and welcome to the SAS Community 🙂

 

Here is one way

 

data test;
input title $ 1-26 year type $;
datalines;
A Midsummer Night's Dream 1595 comedy
Comedy of Errors          1590 comedy
Hamlet                    1600 tragedy
Macbeth                   1606 tragedy
Richard III               1594 history
Romeo and Juliet          1596 tragedy
Taming of the Shrew       1593 comedy
Tempest                   1611 romance
;
User_Help
Obsidian | Level 7

Hi " 

 

Tom
Super User Tom
Super User

To get your posts to look better make sure to use the Insert Code or Insert SAS Code button on the forum editor.  That will put the proper HTML tags around the characters to prevent them from being interpreted as just normal paragraphs that should be reflowed to fit the display window.

 

Kurt_Bremser
Super User

There are three methods to read textual data

  • fixed columns. This is what @PeterClemmensen suggested
  • delimiters that do not appear in data
  • if delimiters (e.g. blanks) appear in data, have quotes around those fields
novinosrin
Tourmaline | Level 20

Hi @User_Help   Good question to refresh my basics. Thank you for that

 


data test;
  length Title $26;
     input @;
	 Title=substr(_infile_,1,anydigit(_infile_)-1);
	 input @(anydigit(_infile_)) year 4. Type :$8.;
     datalines;
A Midsummer Night's Dream 1595 comedy
Comedy of Errors 1590 comedy
Hamlet 1600 tragedy
Macbeth 1606 tragedy
Richard III 1594 history
Romeo and Juliet 1596 tragedy
Taming of the Shrew 1593 comedy
Tempest 1611 romance
;
run;
User_Help
Obsidian | Level 7
Mind to share steps to make fixed column?
Kurt_Bremser
Super User

You don't "make it", you ask the sender to give you data in a usable format. Only if you export data, it's up to you to do that in a proper way:

data test;
input title $ 1-26 year type $;
datalines;
A Midsummer Night's Dream 1595 comedy
Comedy of Errors          1590 comedy
Hamlet                    1600 tragedy
Macbeth                   1606 tragedy
Richard III               1594 history
Romeo and Juliet          1596 tragedy
Taming of the Shrew       1593 comedy
Tempest                   1611 romance
;

filename out temp;

data _null_;
set test;
file out;
put
  title $26.
  " "
  year z4.
  " "
  type $8.
;
run;

/* this step is only there to show you the created datafile */
data _null_;
infile out;
input;
put _infile_;
run;

filename out clear;

Log excerpt:

64         data _null_;
65         infile out;
66         input;
67         put _infile_;
68         run;

NOTE: The infile OUT is:
(sensitive data redacted)
      Zuletzt geändert=10. Oktober 2019 15.14 Uhr,
      Dateigröße (Byte)=328

A Midsummer Night's Dream  1595 comedy  
Comedy of Errors           1590 comedy  
Hamlet                     1600 tragedy 
Macbeth                    1606 tragedy 
Richard III                1594 history 
Romeo and Juliet           1596 tragedy 
Taming of the Shrew        1593 comedy  
Tempest                    1611 romance 
NOTE: 8 records were read from the infile OUT.
      The minimum record length was 40.
      The maximum record length was 40.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.01 seconds

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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
  • 7 replies
  • 892 views
  • 0 likes
  • 5 in conversation