{smcl} {hline} help for {cmd:keyby}{right:(Roger Newson)} {hline} {title:Key the dataset by a variable list} {p 8 21 2} {cmd:keyby} {varlist} [ , {cmdab::no}{cmdab:o:rder} {cmdab:m:issing} {cmdab:fast:} ] {title:Description} {pstd} {cmd:keyby} sorts the dataset currently in memory by the variables in a {varlist}, checking that the variables in the {varlist} uniquely identify the observations. This makes the variables in the {varlist} a primary key for the dataset in memory. If the user does not specify otherwise, then {cmd:keyby} also reorders the variables in the {varlist} to the start of the variable order in the dataset, and checks that all values of these variables are nonmissing. {cmd:keyby} can be useful if the user combines multiple datasets using {helpb merge}, which may cause a dataset in memory to become unsorted. {title:Options} {p 4 8 2} {cmd:noorder} specifies that the variables in the {varlist} are not reordered to the beginning of the variable order of the dataset in memory. If {cmd:noorder} is nor specified, then the variables in {varlist} are reordered to the beginning of the variable order (see {helpb order}). {p 4 8 2} {cmd:missing} specifies that missing values in the variables in the {varlist} are allowed. If {cmd:missing} is not specified, then missing values in the variables in the {varlist} cause {cmd:keyby} to fail. {p 4 8 2} {cmd:fast} is an option for programmers. It specifies that {cmd:keyby} will take no action to restore the existing dataset in memory in the event of failure. If {cmd:fast} is not specified, then {cmd:keyby} will take this action, which uses an amount of time depending on the size of the dataset in memory. {title:Examples} {p 8 12 2}{cmd:. keyby foreign make}{p_end} {p 8 12 2}{cmd:. keyby foreign make, noorder}{p_end} {p 8 12 2}{cmd:. keyby rep78 make, missing}{p_end} {title:Author} {pstd} Roger Newson, National Heart and Lung Institute, Imperial College London, UK.{break} Email: {browse "mailto:r.newson@imperial.ac.uk":r.newson@imperial.ac.uk} {title:Also see} {p 4 13 2} {bind: }Manual: {hi:[D] sort}, {hi:[D] gsort}, {hi:[D] merge}, {hi: [D] order}, {hi:[U] 12.2.1 Missing values} {p_end} {p 4 13 2} On-line: help for {helpb sort}, {helpb gsort}, {helpb merge}, {helpb order}, {helpb missing} {p_end}