Hi all,
I have been tasked with opening and reading xpt files in C#. Using code similar to this has worked great so far:
var tf = new TransportFile(@"x:\temp\shoes.xpt"); var x = tf.Datasets;
However, when accessing the tf.Datasets[0].Data.Rows, this only ever finds the first 100 rows of data. Does anyone know why this could be and a way to fix this? I know for a fact there are more rows with the particular file that I am opening. The version of SAS.UV.Transport is based on SAS Universal Viewer version 1.5.
Thank you in advance!
Adam
So can you tell from this DLL what parameters the function takes?
I would assume that it has a default of returning data in 100 observation chunks.
So perhaps there is a parameter to tell it to return more. Or to tell to start from observations 101 so that you can read it in chunks and put it back together.
Hi @aneemo,
I don't know the answer to this, but I need to point out that SAS does not support the use of SAS Universal Viewer assemblies in this way. These are undocumented internal routines not supported for customers to use in other applications.
If the SAS Universal Viewer supports the function properly in its UI, that's the way to go. I get that you are probably trying to automate this...but we are limited in the support we can offer. (But...does not prevent you from trying or waiting for other community answers.)
Hello Chris!
Thank you for the feedback, this is no problem at all! I completely understand there would not be an support for this...just wanted to see if anyone might have seen this before or have a hint on something to try.
Thank you!
Adam
This is a dumb question, but am I correct in assuming the Universal Viewer itself can display all rows in the XPT file you are testing with?
Ha, that was the first thing I checked to make sure when I saw this error and yes, the Universal Viewer does display all rows. I also have a tool to convert this file to csv and all the rows are in the resulting csv file as well.
I also made sure to close the application to be sure the file is not accessed in any other way and that did not help either.
I did also test with another file that has >100 rows and the exact same thing happens with this other file as well. I am testing in Visual Studio 2022 Profession Version 17.5 and .NET Framework 4.8 if that makes a difference.
Another dumb question...I assume you are taking this path because you don't have a SAS installation that can import the XPT files the "normal" way? If you do have at least one SAS installation that can translate the files, then you could consider converting them into a form your application can work with rather than using unsupported techniques.
Hello, thank you for the reply...I guess I am being stubborn with this. Your suggestion is certainly a way that we could go, it's just the group is used to working with xpt files and that's what I was told to use for this project. I will check with them to see if converting them to another format would be an option if I can't get this to work soon.
Thanks!
So can you tell from this DLL what parameters the function takes?
I would assume that it has a default of returning data in 100 observation chunks.
So perhaps there is a parameter to tell it to return more. Or to tell to start from observations 101 so that you can read it in chunks and put it back together.
I think you are right to check this more closely! I looked into the SASDataset object specifically and there is a Fetch method:
public abstract DataTable Fetch(long start, int count);
Using this I seem to be able to get all the records from the dataset:
dataset[0].Fetch(0, (int)dataset[0].RowCount);
Not the cleanest code I know, but for my testing it does seem to work. I really appreciate your taking time to reply as well as everyone else. I think this is the solution after all!
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.