Skip to content

Instantly share code, notes, and snippets.

@maravedi
Last active May 10, 2016 18:18
Show Gist options
  • Save maravedi/3604e09bd6d24a2483f96c52d4a44b6a to your computer and use it in GitHub Desktop.
Save maravedi/3604e09bd6d24a2483f96c52d4a44b6a to your computer and use it in GitHub Desktop.
<# This is a powershell script to create dummy variables for SAS
The dataset used is the SASHELP.CARS data set, and this script
was used to follow along with the tutorial here:
http://support.sas.com/resources/papers/proceedings12/333-2012.pdf
#>
$d = @(
"All",
"Front"
)
$m = @(
"Acura",
"Audi",
"BMW",
"Buick",
"Cadillac",
"Chevrolet" ,
"Chrysler",
"Dodge",
"Ford",
"GMC",
"Honda",
"Hummer",
"Hyundai",
"Infiniti",
"Isuzu",
"Jaguar",
"Jeep",
"Kia",
"Land Rover",
"Lexus",
"Lincoln",
"MINI",
"Mazda",
"Mercedes-Benz",
"Mercury",
"Mitsubishi",
"Nissan",
"Oldsmobile",
"Pontiac",
"Porsche",
"Saab",
"Saturn",
"Scion",
"Subaru",
"Suzuki",
"Toyota",
"Volkswagen"
)
$t = @(
"Hybrid",
"SUV",
"Sedan",
"Sports",
"Truck"
)
$i = 1;
foreach ($x in $d) {
$x = "IF DriveTrain = '$x' THEN dummy$i=1 ; ELSE dummy$i=0;";
Write-Host $x;
$i++;
}
$i = $d.Count + 1;
foreach ($x in $m) {
$x = "IF Make = '$x' THEN dummy$i=1 ; ELSE dummy$i=0;";
Write-Host $x;
$i++;
}
$i = ($d.Count + $m.Count)+1;
foreach ($x in $t) {
$x = "IF Type = '$x' THEN dummy$i=1 ; ELSE dummy$i=0;";
Write-Host $x;
$i++;
}
$i = 1;
foreach ($x in $d) {
$x = "LABEL dummy$i = '_$x';"
Write-Host $x;
$i++;
}
$i = $d.Count + 1;
foreach ($x in $m) {
$x = "LABEL dummy$i = '_$x';"
Write-Host $x;
$i++;
}
$i = ($d.Count + $m.Count)+1;
foreach ($x in $t) {
$x = "LABEL dummy$i = '_$x';"
Write-Host $x;
$i++;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment