I need to change the field attributes for a lot many .csv files that I'm importing into SAS by the import step in a project. It's very cumbersome the way I'm doing it by modifying the import step, and getting to the field attributes and changing the values in the various columns - type, len, informat, format.
Some files have a lot many variables so I need to take 2 or 3 screen shots....when I import the next .csv file, I have to keep the previous screen shot open and change accordingly. Sometimes I lose my place as it's a picture and I can't highlight anything to hold my spot.
For some reason I cannot import these files programmatically in a data step and set the formats and informats as I need them...they have to be done as a step in the project.
Thanks for any help !!
Do the files all have the same columns in the same order?
If so then you can avoid all of the pointing and clicking by writing a program to read the CSV file and then just call it with the name of the file to be read.
If the files do not already exist on the server where SAS is running you can use the file upload task to copy the csv files to the SAS server before running the data step.
PROC Import, or the wizards that call it, does not have many options involving the types or properties of the variables. Basically only for EXCEL it has the option to force everything as text. Otherwise the programming in Proc Import makes GUESSES based on the contents of the file.
For CSV files the LOG will show the data step code that was generated (ugly and verbose but there) to read the csv. You could copy that from the log and paste into the editor then clean up for the given variables by removing line numbers, most of the Formats (dates, time or datetimes excepted) and adjusting the INFORMAT and FORMAT statements to the desired form. Then rerun the code. If multiple CSV have the same structure then change the file name and data set to read different files.
Hi Xinxin,
Suggestions to consider that might be helpful:
1.) In the "Define Field Attributes" window you can Ctrl+LeftMouse to select multiple data variables and modify them together. This is helpful when multiple columns need to be changed to the same attributes.
See the first image below.
2.) If you have multiple TEXT files that are identical in column name and attributes, only the data values are different, then, you can easily change the source data of the Import Data task then just run the Import task w/o having to redo the column attributes. From the Process Flow window right-click on the source data and choose Properties to then Change the source.
See the second image below.
3.) You mentioned your technique was difficult to manage....something about not being able to see your screen shots.
It seems you should just keep a word doc open to save each of your screen shots.
4.) It is not clear why data step or proc import code was not working for you or why you were not able to do it for other reasons. If you are getting errors about SAS not being able to find the file because it is on your local EG client pc and your SAS server is on a remote SASAPP metadata server, then, you could use Tasks > Data > Copy Files task which will allow you to copy one or more files from your EG client up to your SAS server....then run your datastep or proc import code referencing the directory on your SASAPP server.
See the third image below.
I hope that helps.
Regards,
Bill
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.