Hi Everyone,
I import a csv file with the following first row:
Project_name,Labor Category,Location,Project Type,Pay Code,,,,,,,,,,,,,,,,Totals
SAS takes all column name up to Pay Code correct. Then column name turn to "_", then correctly assign VAR7, VAR8... VAR20, Totals
Why my VAR6 turn to "_" ? Please help me to fix.
Thank you so much.
HHCFX
proc import datafile="C:\\_temp\15days.csv"
out=Utime dbms=csv replace; getnames=yes;run;
Please check if there's an embedded blank or some kind in the variable name where proc import pads with _
I see 20 commas in that line. So it looks like you have 21 columns.
What names do you WANT SAS to use for the columns that don't have headers?
Project_name,Labor Category,Location,Project Type,Pay Code,,,,,,,,,,,,,,,,Totals
If you have a simple text file then just write your own data step to read it. No need to use PROC IMPORT and force SAS to guess what is in the file.
Hi,
The problem is that each time of import, the number of column changes.
I will check my data again.
Thanks for your help.
HHCFX
@hhchenfx wrote:
Hi,
The problem is that each time of import, the number of column changes.
I will check my data again.
Thanks for your help.
HHCFX
How are you going to handle this variation? Not sure if PROC IMPORT helps that much, the resulting datasets are still going be different if the input files are different.
Is there a pattern to the variation? For example perhaps the number of columns represents the number of samples taken or the number of days or months of measurement. If there is a pattern then you can write a SAS program to handle the files.
Share examples of the text files, just enough lines (and columns) to show the pattern. Paste the lines of the file into the editor using the pop-up window you get when you click on the {i} (insert code) button on the editor menu bar. That will prevent the forum editor from treating the data as words and sentences and messing up the formatting.
Thanks, Tom.
I will do it.
HHC
Write your own data step and avoid the guessing of proc import.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.