Skip to content

Instantly share code, notes, and snippets.

@statgeek
Last active December 9, 2020 20:33
Show Gist options
  • Save statgeek/77740f7e5ce9c416e08c71dc7af807dc to your computer and use it in GitHub Desktop.
Save statgeek/77740f7e5ce9c416e08c71dc7af807dc to your computer and use it in GitHub Desktop.
SAS - Create Dummy or Indicator variables for codes
/*Modified from this question on SO: https://stackoverflow.com/questions/65219061/sas-loop-create-columns-from-the-records-which-are-having-a-value
Initial answer from Richard D.
*/
*sample data;
data have;
input id found code $;
datalines;
1 1 001
2 0 v58
3 1 v58
4 1 003
5 0 v58
;
*transpose and move found to the inner values;
proc transpose data=have out=temp(drop=_name_) prefix=code_;
by id;
id code; * column name becomes <prefix><code>;
var found;
run;
* missing occurs when an id was not diagnosed with a code;
* if that means the flag should be zero (for logistic modeling perhaps)
* the missings need to be changed to zeroes;
proc stdize data=temp out=want missing=0 reponly;
var code_:;
run;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment