- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
From an imported tables, how can i create a new table that contains some columns?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Use a data step, and the KEEP statement.
data want;
set have;
keep a b c;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
thank you for your reply but columns will be imported from multiple tables not just one
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Please don't hand out information in little bits and keep us guessing. Describe your issue as a whole.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
From the tables, i have to create a new table that contains the columns following: "account", "code", "country_label", "product_type", value.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I have an other question if you can help please
I want to classify account column by product then by country and do a graph.
How i can do that?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
/exports) by product then by country
then i should do a graph to the results
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content