BookmarkSubscribeRSS Feed
riccardo88
Calcite | Level 5

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...)?

 

Fructose_community.jpg

 

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

2 REPLIES 2
ballardw
Super User

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.

Kurt_Bremser
Super User

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.

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 552 views
  • 0 likes
  • 3 in conversation