BookmarkSubscribeRSS Feed
luigipugliese
Calcite | Level 5

Dear all,

 

When I read the CSV file as text in SAS Studio, I notice that the first row, which is the variables names, extend to the second row of my file. As a result, I am getting no rows when I tried to create a table for SAS. Can you help on how to resolve this problem?

 

Thanks!

6 REPLIES 6
Reeza
Super User

How are you importing your data? Did you specify FIRSTOBS=2 to avoid the header row?

 


@luigipugliese wrote:

Dear all,

 

When I read the CSV file as text in SAS Studio, I notice that the first row, which is the variables names, extend to the second row of my file. As a result, I am getting no rows when I tried to create a table for SAS. Can you help on how to resolve this problem?

 

Thanks!


 

ballardw
Super User

Look at the file in a text editor such as  Wordpad, Notepad or even the SAS editor. Are there two lines of headers there?

If so you may need to tell SAS to start reading data at the third row and your header information for variable names may need some adjustment. Either edit the text file so the headers are not on two lines or use one of the SAS tools to rename the variables after the data is imported.

 

I suspect your data may have originated in a spread sheet where either the headers were in two cells or one of the headers had a line feed in it to make a stacked cell.

If you data looks something like this (note the comma on the first line in the first position) your data likely had a two-cell header

,Two cell,
id ,Header,other value
123,456,789

If that is the case then one option is the edit the CSV so the header is corrected such as:

 

id ,Two cell Header,other value
123,456,789

and import the corrected file.

 

 

If the file looks like this then a line feed was inserted into a cell.

id ,Stacked
 Header,other value
123,456,789

edit by backspacing at the first column in the second line to get

 

id ,Stacked Header,other value
123,456,789

and then import.

 

 

If neither of these matches you problem then copy the first three lines of the data from a text editor such as Notepad (definitely not Excel) and paste into a code box opened using the {I} icon on the forum message window header row so we can see what may be going on.

luigipugliese
Calcite | Level 5

Thank you for your inputs, but I am stil having the same problem. So my csv file looks like this.

 

especialidad,edad,sexo,reserva_mes_d,reserva_dia_d,reserva_hora_d,creacion_mes_d,

creacion_dia_d,creacion_hora_d,latencia,canal,tipo,show

76,66,1,1,1,18,12,4,14,18,1,1,0

76,66,1,1,1,19,12,5,11,17,1,1,0

 

Screen Shot 2018-03-02 at 7.18.01 PM.png

luigipugliese
Calcite | Level 5

I could resolve the issue by uploading it as a  .xls file but not as a csv file. Thank you so much tho for everything.

ballardw
Super User

Upload such things as a simple TXT file.

Or simply from a TEXT editor copy and paste into the Codebox I mentioned previously the first 3 or 4 lines of data. The code box is important as the main message windows will reformat pasted text and do not actually represent your CSV file anymore.

 

Did you try going to the end of the first line and deleting the last character? That should have all of the header on one row.

 

What code did you use: show the LOG.

 

 

 

Tom
Super User Tom
Super User

For such a simple file do NOT use proc import.  Just read it.

data want ;
  infile 'myfilename' dsd truncover firstobs=3;
  input especialidad edad sexo 
        reserva_mes_d reserva_dia_d reserva_hora_d 
        creacion_mes_d creacion_dia_d creacion_hora_d 
        latencia canal tipo show
  ;
run;

 If it turns out that by starting on line 3 you are missing the first row of actual data then your header line was not actually wrapped onto two lines in your file.  It just looked that way because it was longer than the screen you where using to view it.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 2798 views
  • 0 likes
  • 4 in conversation