BookmarkSubscribeRSS Feed
BrahmanandaRao
Lapis Lazuli | Level 10
	proc import datafile ="C:\Users\Anand\Desktop\covid19 updated_onMar31-2020.xlsx"
	out=covid19 
	dbms=xlsx;
	run;



data covid19a;
set covid19;
where Reporting_Country_Territory_Area in ('Western Pacific Region' 'South-East Asia Region');
proc print;
run;

Hi guys 

gentle remainder 

but i didn't get proper solutions 

please find below attachment  and i want retrive information 

two regions only 

 

 

'Western Pacific Region' 'South-East Asia Region'

i want above two regions countries data

 

 

6 REPLIES 6
andreas_lds
Jade | Level 19

Are there any unexpected notes, warnings or errors in the log? If so, please post the log as text using "insert code" button.

Kurt_Bremser
Super User

I stored your Excel file in my UE directory, and ran this:

proc import
  datafile ="/folders/myfolders/covid19 updated_onMar31-2020.xlsx"
  out=covid19 
  dbms=xlsx
  replace
;
run;

data covid19a;
set covid19;
where Reporting_Country_Territory_Area in ('Western Pacific Region' 'South-East Asia Region');
run;

proc print data=covid19a noobs;
run;

and I got the two observations that match your WHERE condition.

BrahmanandaRao
Lapis Lazuli | Level 10
Post output what you have got
I want all countries in both regions
Kurt_Bremser
Super User

@BrahmanandaRao wrote:
Post output what you have got
I want all countries in both regions

With the current structure, this is not possible. It seems that you need to convert a report-style layout to a correct table:

proc import
  datafile ="/folders/myfolders/covid19 updated_onMar31-2020.xlsx"
  out=covid19 
  dbms=xlsx
  replace
;
run;

data covid19_expanded;
length region $47;
set covid19;
retain region;
if
  total_confirmed_cases = . /* "region" line */
then do;
  if reporting_country_territory_area ne "Territories**"
  /* otherwise the two "Territories**" groups form their own region */
  then region = reporting_country_territory_area;
  delete; /* we don't want this extra observation in the dataset */
end;
run;

data want;
set covid19_expanded;
where region in ('Western Pacific Region' 'South-East Asia Region');
run;

 

quran
Calcite | Level 5
proc import datafile ="C:\Users\Anand\Desktop\covid19 updated_onMar31-2020.xlsx"
	out=covid19 
	dbms=xlsx;
run;
data covid19a;
  set covid19;
  where Reporting_Country_Territory_Area in ('Western Pacific Region', 'South-East Asia Region');
run;
proc print data=covid19a;
run;

This code will:

  1. Import the data:

    • Reads the Excel file covid19 updated_onMar31-2020.xlsx from the specified path.
    • Creates a SAS dataset named covid19 from the imported data.
  2. Filter the data:

    • Creates a new dataset covid19a containing only the rows where the regionReporting_Country_Territory_Area is either 'Western Pacific Region' or 'South-East Asia Region.'.
  3. Print the filtered data:

    • Displays the contents of the covid19a dataset.

This refined code addresses the issue in the original code by correctly specifying the where clause to filter for the two desired regions. 

mkeintz
PROC Star

@quran 

 

You may have missed the objective of the original poster, or perhaps didn't notice the structure of the data.

 

The OP wanted "every country" in the two specified regions.  But unfortunately there is no Excel column (thus no imported SAS variable) that identifies the region for every observation.  Instead, there are rows with the region identified in the variable Reporting_Country_Territory_Area.  Luckily the word "Region" appears in this variable for all such rows and only those rows.

 

Following those rows are a series of countries (also identified in Reporting_Country_Territory_Area) that belong to the identified region.

 

Your code retrieves only the two rows that identify the desired regions, but none of the rows following them.  That is what @Kurt_Bremser 's code addresses.

 

If you intend to make the subset for WANT directly from COVID19 imported dataset, then:

 

data want;
  set covid19 ;
  length region $47;
  retain region;

  if findw(Reporting_Country_Territory_Area,'Region') then region=reporting_country_territory_area;
  else if region in ('Western Pacific Region' 'South-East Asia Region') then output;
run;

 

Or you can just create the COVID19_EXPANNDED data set:

 

data covid19_expanded;
  set covid19 ;
  length region $47;
  retain region;

  if findw(Reporting_Country_Territory_Area,'Region') then region=reporting_country_territory_area;
  else output;
run;

Then you could use the WHERE filter that you propose.

 

 

 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1696 views
  • 0 likes
  • 5 in conversation