Now, I would to retrieve the maximum value of Unique_obs per A and B combination. For example..for the first three rows of the above hypothetical dataset (A=100.0, B=70.0), the max value of the Unique_obs is 32.0; for the rows 4-6 (A=105.0; B=70.0), the max value of Unique_obs is 22.0 and for rows 7-9 (A=110.0; B=70.0), max value is 21.0.
I would like to retrieve the max. value of Unique_obs for each combination of A and B such that SAS selects and outputs the whole row containing the max. value observation (ex: 1, 8, 31, 100.0, 70.0, 32.0). Can anybody offer an advice? Do I use PROC SQL? Thank you.
Thank you for the response. I have another question related to my previous query. I have raw data in large text files in the data format as described in my previous posting. I was wondering what would be the syntax in PROC SQL to be used for retrieving data from text files (similar to an 'infile' statement in the data step that can be used to read data from text files into SAS). Can anybody advise? Thanks in advance.
There is no equivalent to a DATA step and INFILE / INPUT statement processing with PROC SQL. The SAS support website has technical papers on this topic - one is listed below (as a link). In this paper, there is an illustration of how you must code a PROC SQL invocation to load a table, but it would be from instream textual data content, not a "flat file" type of input.
Thanks for the information. My knowledge of SQL in SAS is minimal, so I am little unwilling to further proceed in analyzing my data using SQL. However, I am very comfortable using other procedures in SAS and have adequate knowledge to enable me to understand the logic behind the SAS codes.
I would like to briefly explain the data structure that I am working with and the end result I would like to achieve using these data sets.
I have a single text file containing temperature observations from five thousand locations, for one year, in this format: year, month, day, latitude, longitide, temperature. Therefore, each location, that has a unique combination of latitude and longitude, has daily temperature observations for one year. Now, I would like to select a row (year, month, day, latitude, longitude, temperature) that has the maximum value of temperature for that location for the entire year. Like that, I need the maximum value of temperature, for each of the 5000 locations, to be saved in a single text file.
The SAS code I used:
infile 'C:\work\xyz.txt' dlm=',' firstobs=2;
input year month day lat long maxtemp;
proc sort data=abc out=tmp1;
by lat long maxtemp;
data abc1; set tmp1;
by lat; if last.lat = 1;
proc print data=abc1;
Although, the SAS log doesn't show any problem, I am unable to get the max. temperature values for all the locations. Any offer of advice will be greatly appreciated.
I think the neatest solution is to combine your first data step import the data into sas, can be done as a view if wish not to store your data twice. Then use the above suggested SQL on that table/view.
Thanks Binod and Linus. Although I was a little reluctant to use Proc SQL earlier, eventually I did, and it was far faster than the Data step of SAS. I added a few other things such as creating a table in SQL and exporting the resultant output as an MS Access file using the Export Wizard in SAS. It worked great and the SQL procedure took less than a minute to output the results. Way to go!!