I've been looking for a way to value/change a table's description through a program/code instead of the UI. The table description is on the General tab of the table properties. Everything I've found shows how to through UI but nothing through code. Is this possible?
That's actually the dataset label. That can be added a few ways, basically anywhere you write the dataset, or PROC DATASETS.
proc datasets lib=work;
modify want(label="Want Label");
quit;
Or
data class(label="Class Dataset");
set sashelp.class;
run;
Related
Is there an equivalent to the SAS format cntlin procedure in Teradata. I have a reference value table (code_value), which is used a lot and rather than doing many outer joins to the reference value table, I'd like to have a lookup function similar to the solution below in SAS. Any help is greatly appreciated.
data CodeValueFormat;
set grp.code_value (keep=code_value_id description);
fmtname = 'fmtCodeValue';
start = code_value_id;
label = description;
run;
proc format cntlin=work.codevalueformat;
run;
proc sql;
select foo_code_id format=fmtCodeValue.
from bar;
quit;
There is no way you can emulate SAS format cntlin procedure in Teradata or any other database other than using lookup tables. One way to avoid doing same joins again and again is to do index join. please look into below link to see whether this is what you want to do. https://info.teradata.com/HTMLPubs/DB_TTU_16_00/index.html#page/Database_Management%2FB035-1094-160K%2Fqiq1472240587768.html%23wwID0EFK1R
One another way is to maintain a denormalized table and do joins with your incremental/daily records in your staging area and then append this records to your final table
I have a simple data table in SAS, where I have the results from a survey I sent to my friends:
DATA Questionnaire;
INPUT make $ Question_Score ;
CARDS;
Ned 1
Shadowmoon 2
Heisenberg 1
Athelstan 4
Arnold 5
;
RUN;
What I want to do, using SAS, is to export this table into SPSS (.sav), and also have the value labels for the Question_Score, like shown in the picture below:
I then proceed to create a format in SAS (in hope this would do it):
PROC FORMAT;
VALUE Question_Score_frmt
1="Totally Agree"
2="Agree"
3="Neutral"
4="Disagree"
5="Totally Disagree"
;
run;
PROC FREQ DATA=Questionnaire;
FORMAT Question_Score Question_Score_frmt.
;
TABLES Question_Score;
RUN;
and finally export the table to a .sav file using the fmtlib option:
proc export data=Questionnaire outfile="D:\Questionnaire.sav"
dbms=spss replace;
fmtlib=work.Q1frmt;
quit;
Only to disappoint myself seeing that it didn't work.
Any ideas on how to do this?
You didn't apply the format to the dataset, unfortunately, you applied it to the proc freq. You would need to use PROC DATASETS or a data step to apply it to the dataset.
proc datasets lib=work;
modify questionnaire;
format Question_Score Question_Score_frmt.;
run;
quit;
Then exporting will include the format, if it's compatible in SAS's opinion with SPSS's value label rules. I will note that SAS's understanding of SPSS's rules is quite old, based on I think SPSS version 9, and so it's fairly often that it won't work still, unfortunately.
I'm new to SAS and have some problems with adding a column to existing data set in SAS using MODIFY statement (without proc sql).
Let's say I have data like this
id name salary perks
1 John 2000 50
2 Mary 3000 120
What I need to get is a new column with the sum of salary and perks.
I tried to do it this way
data data1;
modify data1;
money=salary+perks;
run;
but apparently it doesn't work.
I would be grateful for any help!
As #Tom mentioned you use SET to access the dataset.
I generally don't recommend programming this way with the same name in set and data statements, especially as you're learning SAS. This is because it's harder to detect errors, since once run and encounter an error, you destroy your original dataset and have to recreate it before you start again.
If you want to work step by step, consider intermediary datasets and then clean up after you're done by using proc datasets to delete any unnecessary intermediary datasets. Use a naming conventions to be able to drop them all at once, i.e. data1, data2, data3 can be referenced as data1-data3 or data:.
data data2;
set data1;
money = salary + perks;
run;
You do now have two datasets but it's easy to drop datasets later on and you can now run your code in sections rather than running all at once.
Here's how you would drop intermediary datasets
proc datasets library=work nodetails holist;
delete data1-data3;
run;quit;
You can't add a column to an existing dataset. You can make a new dataset with the same name.
data data1;
set data1;
money=salary+perks;
run;
SAS will build it as a new physical file (with a temporary name) and when the step finishes without error it deletes the original and renames the new one.
If you want to use a data set you do it like this:
data dataset;
set dataset;
format new_column $12;
new_column = 'xxx';
run;
Or use Proc SQL and ALTER TABLE.
proc sql;
alter table dataset
add new_column char(8) format = $12.
;
quit;
I have a sas7bdat table that contains format information but I do not have the formats, so lots of the data appears as * and doesn't make much sense. I know the informat data that lies beneath is there — how can I remove all formats from the table?
There is another way in addition to #JustinDavies's answer that is to use PROC DATASETS procedure.
Adapted from the SAS documentation: Example 1: Removing All Labels and Formats in a Data Set
proc datasets lib=<your library> memtype=data nolist;
modify <your dataset>;
attrib _all_ label=' ';
attrib _all_ format=;
attrib _all_ informat=;
run;
The advantage in using PROC DATASETS is that it modifies the dataset's metadata in-place - i.e., it is not going to create a new dataset as suggested in the other answer to this question. That feature could be of advantage if your dataset is large.
The following code will strip all formatting from the table FORMATTED_TABLE and create a new table named UNFORMATTED_TABLE
data UNFORMATTED_TABLE;
set FORMATTED_TABLE;
format _all_;
run;
I have a timeseries dataset in SAS and I am running this data through the UCM procedure to identify signficiant structural breakpoints in the timeseries (changes in the expected mean).
My code is as follows:
proc ucm data=temp;
by source;
id date interval=month;
model baseload;
irregular;
level checkbreak;
run;
The level checkbreak statement above is printed in the SAS output window in the section labeled 'outlier summary', but I need the output in a dataset. The 'outest' statement only works for the 'estimate' statement and not the level statement in proc UCM. Does anyone know know if it is possible to write this section out to a dataset?
You can access the OutlierSummary table using SAS's ODS system.
Read about it here:
http://support.sas.com/documentation/cdl/en/etsug/60372/HTML/default/viewer.htm#etsug_ucm_sect034.htm