Hallo!
I have to import some csv files and the device I used to collect the data creates csv files with a strange format with some information on the side (see image). Is there any way to create new variables with those informations (e.g. ID=G, Sex=Male, Age=25, etc...)?
You can find 3 csv file in the attachments section and this is the code I used to import them.
data want;
infile "FolderHave\*csv"
dlm=','
missover
dsd;
input one $ two $ three $ four $ five $ six $ seven $ eight $ nine $ time $ VP VO2 VCO2 R VO2divKg METS
HF VO2divHF FeO2 FeCO2 FiO2 FiCO2 PeO2 PeCO2 SpO2 Phase $ Marker $ UmgebTemp RHUmgeb
Sensordruck PB EEkc EEh EEm EEtot EEkg PRO FETT KH PROprc FETTprc KHprc npRQ tRel
Phasenzeit $ VO2prcSoll;
run;
My SAS version is 9.4.
Thank you very much for your help!!!
Riccardo
You may have other issues in play as well.
I attempted to open one your attachments and got a message that the file format does not match the file extension.
It may be time to talk to the source of those files or look into the options used to write the data from the device.
I would also look at those files with a plain text editor not a spreadsheet. Spreadsheets are know to modify some data when opening CSV without telling you it has done so. And if the file was saved from the spreadsheet then the data may be corrupted from what it should be.
You would really have to describe any rules for which values of "one", "four" or "seven" are required to identify the desired values of "two" "five" and "eight".
Plus describe what goes on with the other variables.
You should show what the resulting output data set should look like.
First, determine where the real data starts, column-wise.
Read all "columns" before that with sufficiently long character variables to not lose data. Drop those variables so that they do not clutter up the output.
In the data step, create two datasets. One to hold the table, the other to hold the "customer data".
Retain the variables needed for the "customer data", and assign values to them according to what you find, whenever you find it.
output the "table" dataset for every input line, but output the other only at the end.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.