0

Hey I am trying to import .wpd sas dataset in python. But unable to get the solution. Can anyone please help me out on this.

I have tried it using below class in python: import json import numpy as np class JSONData: def init(self, filename): with open(filename) as data_file:self.data = json.load(data_file)

def getDatasetCount(self):
    return len(self.data['wpd']['dataSeries'])

def getDatasetByIndex(self, index):
    return self.data['wpd']['dataSeries'][index]

def getDatasetByName(self, name):
    return [x for x in self.data['wpd']['dataSeries'] if x['name'] == name][0]

def getDatasetNames(self):
    return [x['name'] for x in self.data['wpd']['dataSeries']]

def getDatasetValues(self, dataset):
    values = []
    for val in dataset['data']:values.append(val['value'])
    return np.array(values)

But no luck. Thanks in Advance.....

Reeza
  • 20,510
  • 4
  • 21
  • 38
Ashish
  • 55
  • 1
  • 1
  • 6
  • You can try this approach but WPD is a proprietary data set from a SAS copycat so no idea if the file structure is the same. https://www.anegron.site/2018/11/27/read-sas-datasets-in-python/ – Reeza Nov 25 '20 at 16:38
  • Thanks, but its not working – Ashish Nov 25 '20 at 18:38
  • Do you think it would be helpful to show what you actually tried and if you received an error? Not working could mean anything from your computer exploded to you missed a period or space. – Reeza Nov 25 '20 at 19:08
  • FYI - I changed the tags to be WPS as this isn't actually related to SAS at all. – Reeza Nov 25 '20 at 19:11

1 Answers1

1

WPS allows you to save a sas7bdat file. I recommend using WPS to create a new file instead of trying to get the WPS file read.

Then pandas, a python extension, can read sas sas7bdat files as a dataframe

https://pandas.pydata.org/docs/reference/api/pandas.read_sas.html

Paul Brennan
  • 2,638
  • 4
  • 19
  • 26