From an imported tables, how can i create a new table that contains some columns?
Use a data step, and the KEEP statement.
data want;
set have;
keep a b c;
run;
Or if you want to keep most of the variables and just remove a few, use Drop
data want; set have; drop P D Q; run;
thank you for your reply but columns will be imported from multiple tables not just one
Please don't hand out information in little bits and keep us guessing. Describe your issue as a whole.
i have a set of tables in my sas studio, from these tables i want to create a table which contains specific columns. and these columns do not belong to the same table
So you probably need to merge or join the tables. Please show some examples for the tables, and what you intend to get as a result.
From the tables, i have to create a new table that contains the columns following: "account", "code", "country_label", "product_type", value.
So what you do is a so-called "lookup" (expanding a code to a derived value).
There are several methods for doing this:
A SQL join:
proc sql;
create table want as
select
a.account,
a.code,
b.country_label,
a.product_type,
a.value
from gsquarterly_december_2020 a
left join
country_classification b
on a.country_code = b.country_code
;
quit;
Create a format:
data cntlin;
set country_classification;
fmtname = "country_label";
type = "C";
rename
country_code=start
country_label=label
;
keep fmtname type start label;
run;
data want;
set have;
country_label = put(country_code,country_label.);
keep account code country_label product_type value;
run;
A data step merge:
proc sort data=country_classification;
by country_code;
run;
proc sort data=gsquarterly_december_2020;
by country_code;
run;
data want;
merge
gsquarterly_december_2020 (in=a)
country_classification
;
by country_code;
if a;
keep account code country_label product_type value;
run;
or, most modern, a hash object:
data want;
set gsquarterly_december_2020;
if _n_ = 1
then do;
length country_label $30; /* use appropriate length here */
declar hash cc (dataset:"country_classification");
cc.definekey("country_code");
cc.definedata("country_label");
cc.definedone();
end;
if cc.find() ne 0 then country_label = "";
keep account code country_label product_type value;
run;
Please supply an example for your dataset in a data step with datalines, so I have something to work with.
Describe how your graph should look like (line,bar,...) and what should be the X and Y axis values.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.