DATA Step, Macro, Functions and more

replacing obs or converting arrays from char to numeric

Accepted Solution Solved
Reply
Contributor
Posts: 61
Accepted Solution

replacing obs or converting arrays from char to numeric

Hi,

 

When I am importing a file into SAS the variable are being converted from numeric to character....This is probably because missing observations are represented with  "." .Is there anyway I can replace "." with a " " (that is a blank value). I know this can be simply done in excel but excel is also removing "'." from my numeric data set that is replacing :e.g 3.2756 to 32756. Any suggestions how to handle it? Please note that I have more than 6000 variables in my data set.


Accepted Solutions
Solution
‎06-18-2018 05:26 AM
Super User
Posts: 10,270

Re: replacing obs or converting arrays from char to numeric

Save the spreadsheet to a text (eg csv) file, import that, then take the data step found in the SAS log and adapt the variables in question to your needs.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code

View solution in original post


All Replies
Solution
‎06-18-2018 05:26 AM
Super User
Posts: 10,270

Re: replacing obs or converting arrays from char to numeric

Save the spreadsheet to a text (eg csv) file, import that, then take the data step found in the SAS log and adapt the variables in question to your needs.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Super User
Super User
Posts: 9,599

Re: replacing obs or converting arrays from char to numeric

Right, I am just looking into my crystal ball, and yes, now I see your data and your process!  How are you importing the data, is it Excel by any chance.  That is often the cause of bad data, consider moving to a proper data format like CSV, or XML, and writing a proper import step to import the data correctly.  This "This is probably because missing observations are represented with  "."" should not matter, as SAS treats . as numeric, unless of course your using proc import or Excel (or even worse, both).

 

" I know this can be simply done in excel but excel is also removing "'." from my numeric data set that is replacing :e.g 3.2756 to 32756." - what does this mean?  What is the datafile you have, what format.  Opening in Excel does not help anyone, Excel has "functionality" which hides real data and shows it how it thinks you want to see it.  Try posting some test data in the form of a text file.

 

"Please note that I have more than 6000 variables" - that is a lot, anything more than a couple of hundred is a lot and will be a real pain to try to work with.  First step for me would be to remodel the data into a workable format (i.e. normalise it all down to a few variables and lots of observations.)

☑ This topic is solved.

Need further help from the community? Please ask a new question.

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